Refactors scheduling logic.