Add state machine functionality
Merge