fix the scheduler and add more unit tests
Merge pull request #465 from racker/fixes/scheduler

fix the scheduler and add more unit tests