Added StateMachine class (with a tests)