Fix logical error in search