Index: tol/btol/bgrammar/spfuninst.cpp
===================================================================
--- tol/btol/bgrammar/spfuninst.cpp	(revision 6a96b5f66db1a6be78c583fc601220807a3696a1)
+++ tol/btol/bgrammar/spfuninst.cpp	(revision 4427439755460cf72772b1298613dee21f1894b5)
@@ -1093,20 +1093,20 @@
 {
   static BText _name_ = "Copy";
-    BSyntaxObject* result = NIL;
-    BInt nb = BSpecialFunction::NumBranches(tre);
-    if(BSpecialFunction::TestNumArg(_name_, 1, nb, 1))
-    {
-	BSyntaxObject* toCopy = gra->EvaluateTree(Branch(tre,1));
-	if(toCopy)
-	{
+  BSyntaxObject* result = NIL;
+  BInt nb = BSpecialFunction::NumBranches(tre);
+  if(BSpecialFunction::TestNumArg(_name_, 1, nb, 1))
+  {
+    BGrammar::IncLevel();
+    int stackPos = BGrammar::StackSize();
+    BSyntaxObject* toCopy = gra->EvaluateTree(Branch(tre,1));
+	  if(toCopy)
+	  {
 	    result = toCopy->CopyContens();
-	    if(result!=toCopy)
-	    {
-		SAFE_DESTROY(toCopy,result);
-	    }
-	}
-    }
-    result=BSpecialFunction::TestResult(_name_,result,tre,NIL,BTRUE);
-    return(result);
+	  }
+    BGrammar::DestroyStackUntil(stackPos, result);    
+    BGrammar::DecLevel();
+  }
+  result=BSpecialFunction::TestResult(_name_,result,tre,NIL,BTRUE);
+  return(result);
 }
 
Index: tol/btol/code_type/codgra.cpp
===================================================================
--- tol/btol/code_type/codgra.cpp	(revision 6a96b5f66db1a6be78c583fc601220807a3696a1)
+++ tol/btol/code_type/codgra.cpp	(revision 4427439755460cf72772b1298613dee21f1894b5)
@@ -47,4 +47,11 @@
 { 
   Contens(); 
+}
+
+//--------------------------------------------------------------------
+  BUserFunCode::BUserFunCode()
+//--------------------------------------------------------------------
+: BContensCode() 
+{
 }
 
Index: tol/btol/code_type/tol_bcodgra.h
===================================================================
--- tol/btol/code_type/tol_bcodgra.h	(revision 6a96b5f66db1a6be78c583fc601220807a3696a1)
+++ tol/btol/code_type/tol_bcodgra.h	(revision 4427439755460cf72772b1298613dee21f1894b5)
@@ -47,4 +47,5 @@
 {
 public:
+  BUserFunCode();
   BUserFunCode(const BText& name, const BCode& aCode, const BText& desc);
   BUserFunCode(const BText& name, BStandardOperator* opr, const BText& desc);
Index: tol/btol/set_type/setgra.cpp
===================================================================
--- tol/btol/set_type/setgra.cpp	(revision 6a96b5f66db1a6be78c583fc601220807a3696a1)
+++ tol/btol/set_type/setgra.cpp	(revision 4427439755460cf72772b1298613dee21f1894b5)
@@ -2265,7 +2265,22 @@
 BSyntaxObject* CopyCode(BSyntaxObject* obj)
 {
-  BCode cod;
-  cod.Replicate(Code(obj));
-  return(new BContensCode("",cod,""));
+  BCode& cod = Code(obj);
+  BUserFunction* opr = (BUserFunction*)cod.Operator();
+  if(opr)
+  {
+    BUserFunction* usf = new BUserFunction("",opr->Grammar());
+    BUserFunCode* result = usf->GetCode();
+    usf->PutName(opr->Name());
+    usf->PutDescription(opr->Description());
+    usf->SetExpression(opr->Declaration(), opr->Definition()); 
+    result->PutName(opr->Name());
+    result->PutDescription(opr->Description());
+    return(result);
+  }
+  else
+  {
+    Error(BText("Cannot copy Code ")<<obj->Identify());
+    return(NULL);
+  }
 };
 /*
