finish search function