Refactoring and adjust scheduler slightly