Fixing a bug in the scheduler where tasks where lost