diff --git a/lib/gtpl_manageronly.js b/lib/gtpl_manageronly.js
index <HASH>..<HASH> 100644
--- a/lib/gtpl_manageronly.js
+++ b/lib/gtpl_manageronly.js
@@ -292,7 +292,6 @@ gtpl.deepCopy = function(data, escapeStringFunction, ignore_prefix, skip_prototy
             return data[recursion_key];
 
             var o = {};
-            data[recursion_key] = o;
             recursion_list.push(data);
 
             if (!skip_prototype) {
@@ -305,6 +304,8 @@ gtpl.deepCopy = function(data, escapeStringFunction, ignore_prefix, skip_prototy
                 }
             }
 
+            data[recursion_key] = o;
+
             var keys = Object.keys(data);
             for (var j = 0; j < keys.length; j++) {
                 var key = keys[j];
@@ -396,4 +397,4 @@ TemplateManager.prototype.import_templates = function(template_export_string, so
             this.__evalTemplates__(template_export_string);
 };
 
-})();
\ No newline at end of file
+})();
Bugfix: don't overwrite temp object