scheduling function

The missing scheduling function and other minor changes.