Extract StateMachine class.