Simple finite state machine.