added state machine to main