refactor out search()