refactor out search