Fix bug in scheduler