diff --git a/ExprNode.cc b/ExprNode.cc
index b3dd523e9993ca4d8e8fc8c430a1c0972b8eedeb..1ccd26d51285cd002957f480a8ee5d25be81f7ed 100644
--- a/ExprNode.cc
+++ b/ExprNode.cc
@@ -2834,7 +2834,13 @@ UnaryOpNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &
   expr_t argsubst = arg->substituteDiff(subst_table, neweqs);
   assert(argsubst != NULL);
 
-  int symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst);
+  int symb_id = -1;
+  VariableNode *vn = dynamic_cast<VariableNode *>(argsubst);
+  if (vn != NULL)
+    symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst, vn->get_symb_id(), vn->get_lag());
+  else
+    symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst);
+
   expr_t newAuxVar = datatree.AddVariable(symb_id, 0);
 
   //AUX_DIFF_IDX = argsubst - argsubst(-1)
diff --git a/SymbolTable.cc b/SymbolTable.cc
index 4b18946c0faa0fd21ca3193a6c0ff6c04327eddd..22f271968c1e0af6ed42a78b2c553c513dda87d1 100644
--- a/SymbolTable.cc
+++ b/SymbolTable.cc
@@ -354,7 +354,6 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
           {
           case avEndoLead:
           case avExoLead:
-          case avDiff:
             break;
           case avEndoLag:
           case avExoLag:
@@ -375,6 +374,11 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
             aux_vars[i].get_expr_node()->writeOutput(output, oLatexDynamicModel);
             output << ")';" << endl;
             break;
+          case avDiff:
+            if (aux_vars[i].get_orig_symb_id() >= 0)
+              output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl
+                     << "M_.aux_vars(" << i+1 << ").orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
+            break;
           }
       }
 
@@ -476,7 +480,6 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException)
             case avExpectation:
             case avMultiplier:
             case avDiffForward:
-            case avDiff:
               break;
             case avEndoLag:
             case avExoLag:
@@ -484,6 +487,11 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException)
               output << "av[" << i << "].orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
                      << "av[" << i << "].orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
               break;
+            case avDiff:
+              if (aux_vars[i].get_orig_symb_id() >= 0)
+                output << "av[" << i << "].orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
+                       << "av[" << i << "].orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
+              break;
             }
         }
     }
@@ -570,7 +578,6 @@ SymbolTable::writeCCOutput(ostream &output) const throw (NotYetFrozenException)
         case avExpectation:
         case avMultiplier:
         case avDiffForward:
-        case avDiff:
           break;
         case avEndoLag:
         case avExoLag:
@@ -578,6 +585,11 @@ SymbolTable::writeCCOutput(ostream &output) const throw (NotYetFrozenException)
           output << "av" << i << ".orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
                  << "av" << i << ".orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
           break;
+        case avDiff:
+          if (aux_vars[i].get_orig_symb_id() >= 0)
+            output << "av" << i << ".orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
+                   << "av" << i << ".orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
+          break;
         }
       output << "aux_vars.push_back(" << "av" << i << ");" << endl;
     }
@@ -695,7 +707,7 @@ SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, expr_t e
 }
 
 int
-SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException)
+SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) throw (FrozenException)
 {
   ostringstream varname;
   int symb_id;
@@ -712,11 +724,18 @@ SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenExcept
       exit(EXIT_FAILURE);
     }
 
-  aux_vars.push_back(AuxVarInfo(symb_id, avDiff, 0, 0, 0, 0, expr_arg));
+  cout << "DIFF: " << orig_symb_id << "(" << orig_lag << ")" << endl;
+  aux_vars.push_back(AuxVarInfo(symb_id, avDiff, orig_symb_id, orig_lag, 0, 0, expr_arg));
 
   return symb_id;
 }
 
+int
+SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException)
+{
+  return addDiffAuxiliaryVar(index, expr_arg, 0, 0);
+}
+
 int
 SymbolTable::addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (AlreadyDeclaredException, FrozenException)
 {
@@ -1027,7 +1046,6 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
             {
             case avEndoLead:
             case avExoLead:
-            case avDiff:
               break;
             case avEndoLag:
             case avExoLag:
@@ -1035,6 +1053,11 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
               output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", "
                      << aux_vars[i].get_orig_lead_lag() << ", NaN, NaN";
               break;
+            case avDiff:
+              if (aux_vars[i].get_orig_symb_id() >= 0)
+                output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", "
+                       << aux_vars[i].get_orig_lead_lag() << ", NaN, NaN";
+              break;
             case avMultiplier:
               output << "NaN, NaN, " << aux_vars[i].get_equation_number_for_multiplier() + 1
                      << ", NaN";
diff --git a/SymbolTable.hh b/SymbolTable.hh
index 53ba84d4990c0096f48edb24433c637f0f8ce223..b754bd96a64454732342608074acb522813fcb3f 100644
--- a/SymbolTable.hh
+++ b/SymbolTable.hh
@@ -286,6 +286,7 @@ public:
   int addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (AlreadyDeclaredException, FrozenException);
   //! Adds an auxiliary variable when the diff operator is encountered
   int addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException);
+  int addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) throw (FrozenException);
   //! Returns the number of auxiliary variables
   int
   AuxVarsSize() const