state machine works in main