Fix some bugs in search