Fixed issue with loop