main scheduler loop and iterators