search and erase function edited