written. time to fix bugs with loop search