use state machine in main schedule funct