Fixed a small bug in the state machine