Could this be encoded in control flow rather than an explicit state machine ?