add search function
fix memory leak