Scheduler improvement

Empirical improvement by a factor of 2.6. Using linear algorithm and
more primitive data structures.