Simplified and fixed the scheduler.