improved code of taskScheduler