optimize the function of searching