better search logic