Refactoring codes for scheduler