clean up state machine