implementation for search and insert