Refactored the example with Cristian Groza to include the declarative FSM.