Fixed error with loop