statemachine implementation