fully working search method