Redesigned scheduler code logic. Closes #903.