Fixed bug in the search algorithm