Some code improvements for the search