Did you consider gen_fsm? gen_fsm lets you maintain the current state (both stage of the state machine and the state data). It simplifies garbage collection: it is possible to set timeouts for each specific stage Info about which particular stage times out is available. The code can then act accordingly.