Fixed bugs in scheduler.