Fixes in the search algorithm