Scheduler fix

Here a proposed solution to the issue #1102
This also includes changes from pull request #1088