slight optimization of search method