Refactoring the scheduler to something much simpler