Change scheduler to use iterators and functors