first pass at cleaning up the search code