Simple finite-state machine.