A recipe for implementing state machines.[1]