Finalizing the search function.