Refactor statemachine into controller and add activate and deactivate methods to the view