Refactor to have better common search code.