diff --git a/Registry.cxx b/Registry.cxx
index 180762d08a1246a0d2f159930703b781d51261c2..e3a110158b155b74556e95ad3f9454cf61383806 100644
--- a/Registry.cxx
+++ b/Registry.cxx
@@ -525,7 +525,7 @@ bool RegistryHelper::Close()
         it != this->EntriesMap.end();
         ++ it )
         {
-        *ofs << it->first.c_str() << " = " << it->second.c_str()<< kwsys_ios::endl;
+        *ofs << it->first.c_str() << " = " << this->EncodeValue(it->second.c_str()).c_str() << kwsys_ios::endl;
         }
       }
     this->EntriesMap.erase(
@@ -660,7 +660,7 @@ bool RegistryHelper::SetValue(const char *skey, const char *value)
       {
       return 0;
       }
-    this->EntriesMap[key] = this->EncodeValue(value);
+    this->EntriesMap[key] = value;
     return 1;
     }
   return false;
@@ -744,7 +744,7 @@ kwsys_stl::string RegistryHelper::EncodeKey(const char* str)
     {
     switch ( *str )
       {
-    case '%': case '=': case '\n': case '\r': case '\t': case ' ':
+    case '%': case '=': case '\n': case '\r': case '\t':
       char buffer[4];
       sprintf(buffer, "%%%02X", *str);
       ostr << buffer;
diff --git a/testRegistry.cxx b/testRegistry.cxx
index f0d7e32bdec9fd791f4083f85a993a01ab838707..e03350825a56e1d45a45510cb4218c4aee0cc659 100644
--- a/testRegistry.cxx
+++ b/testRegistry.cxx
@@ -35,7 +35,7 @@
   kwsys_ios::cout << "Error in: " << #x << kwsys_ios::endl;           \
   }
 
-#define CHE(x,y,res) if ( strcmp(x,y) )                 \
+#define CHE(x,y,res) if ( x && y && strcmp(x,y) )                 \
   {                                                     \
   res = 1;                                              \
   kwsys_ios::cout << "Error, " << x << " != " << y << kwsys_ios::endl;        \
@@ -90,10 +90,14 @@ int main(int, char**)
   IFT(reg.SetValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName",  "TestKey1", longStringWithNewLines), res);
   IFT(reg.ReadValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", &buffer), res);
   CHE(buffer, longStringWithNewLines, res);
+  IFT(reg.DeleteValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName",  "TestKey1"), res);
+  IFNT(reg.ReadValue("TestSubkeyWithVeryLongInFactSoLongItsHardToImagineAnybodyWouldReallyDoItLongName", "TestKey1", &buffer), res);
 
   IFT(reg.SetValue("TestSubkeyWith = EqualSignChar",  "TestKey = 1", "Some value"), res);
   IFT(reg.ReadValue("TestSubkeyWith = EqualSignChar",  "TestKey = 1", &buffer), res);
   CHE(buffer, "Some value", res);
+  IFT(reg.DeleteValue("TestSubkeyWith = EqualSignChar",  "TestKey = 1"), res);
+  IFNT(reg.ReadValue("TestSubkeyWith = EqualSignChar",  "TestKey = 1", &buffer), res);
 
   if ( res )
     {