Improve search algorithm