implement the scheduler loop