scheduler: Code refactoring