Improving search algorithm