Adding a sanity test for scheduler, which also required some refactoring.