Improving search algorithm & ajax