fix bugs regarding deleted keys and non-existent namespaces