Start reworking code to a state machine.