Fixed bug with loop bounds