Improve state machine.