Fix state machine