Fix search in loop