Small fixes in the state machine