More defensive programming for add, clear, search

More defensive programming for add, clear, search