refactor the searching process