Re-designed scheduler to use separate "prescheduler" thread, so that main scheduler is simplified.