Refactor scheduler.