StateMachine class encapsulates the state transitions