simplify statemachine code a little