fix race on state machines