fixes to search algo