Fixed state machine bug