fixed the state machine bug