Fix bug in loop schedule