Final implementation of scheduler