Lightweight finite state machine.