Changed to model functionality to state machine