implementation for lsearch