fixing issue with loop