fix an off by 1 error with loop evaluation