Refactoring. Moving functions to scheduling module