Refactor to use state machine and controllers.