fixed bug with loop search