statemachine design