Reorganized state machine code