improve search and fix some bugs