Fix some bugs in Scheduler and Main