changed search algorithm