added the working version of the StateMachine