Added a state machine