total refactor of scheduler