more fixes to the state machine