add search function and fix some bugs