Rework the engine to implement a basic 4 state machine.