Fixed a bug in the state machine.