changed algorithms to speed up the search feature