simplify the logic in TaskSchedulerImpl