Refactor scheduler