Scheduler code refactoring