Infinite loop when finding results