refactor search in qb