Fixes up state transitions.