Fix for KeyError in search and test