Fix and update state machine