search algorithm corrected