I am a bit reluctant to use the state machine concept as the behavior of the system is not being controlled by any of the past events; rather, it creates some run-time variables that control the future behavior of the system; for example, the flags.
Isn't it -almost- exactly the opposite?
Regards.