Some restructuring of state machine.