Collapsed the search code into a better calling function