A simple state machine.