Refactored the scheduler and added new tests