various fixes related to state machines