fixed bug with loop