Refactoring scheduler module and moving out functions not directly related to the scheduler