Added loopSearch function