WIP state machine code cleanup