diff --git a/preprocessor/DataTree.hh b/preprocessor/DataTree.hh
index 3540a86de253304ae272599e575d9d50c0ff66ee..9ef440f8aebc1b7df56cffd54c2c7980a0938c13 100644
--- a/preprocessor/DataTree.hh
+++ b/preprocessor/DataTree.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003-2012 Dynare Team
+ * Copyright (C) 2003-2014 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -68,10 +68,16 @@ protected:
   binary_op_node_map_t binary_op_node_map;
   typedef map<pair<pair<pair<expr_t, expr_t>, expr_t>, TrinaryOpcode>, TrinaryOpNode *> trinary_op_node_map_t;
   trinary_op_node_map_t trinary_op_node_map;
+
+  // (arguments, symb_id) -> ExternalFunctionNode
   typedef map<pair<vector<expr_t>, int>, ExternalFunctionNode *> external_function_node_map_t;
   external_function_node_map_t external_function_node_map;
+
+  // ((arguments, deriv_idx), symb_id) -> FirstDerivExternalFunctionNode
   typedef map<pair<pair<vector<expr_t>, int>, int>, FirstDerivExternalFunctionNode *> first_deriv_external_function_node_map_t;
   first_deriv_external_function_node_map_t first_deriv_external_function_node_map;
+
+  // ((arguments, (deriv_idx1, deriv_idx2)), symb_id) -> SecondDerivExternalFunctionNode
   typedef map<pair<pair<vector<expr_t>, pair<int, int> >, int>, SecondDerivExternalFunctionNode *> second_deriv_external_function_node_map_t;
   second_deriv_external_function_node_map_t second_deriv_external_function_node_map;
 
diff --git a/preprocessor/ExprNode.cc b/preprocessor/ExprNode.cc
index 6639416fe3ac2d0169e37a30b611c7d1323b5f1b..11d23a6d3778d58feca99909b873f0b17855461f 100644
--- a/preprocessor/ExprNode.cc
+++ b/preprocessor/ExprNode.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2007-2013 Dynare Team
+ * Copyright (C) 2007-2014 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -4935,12 +4935,10 @@ FirstDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
       return;
     }
 
-  int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
+  const int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
   assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
 
-  int tmpIndx = inputIndex;
-  if (IS_C(output_type))
-    tmpIndx = tmpIndx - 1;
+  const int tmpIndx = inputIndex - ARRAY_SUBSCRIPT_OFFSET(output_type);
 
   if (first_deriv_symb_id == symb_id)
     output << "TEFD_" << getIndxInTefTerms(symb_id, tef_terms)
@@ -4982,15 +4980,14 @@ FirstDerivExternalFunctionNode::compile(ostream &CompileCode, unsigned int &inst
   int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
   assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
 
-  int tmpIndx = inputIndex;
   if (!lhs_rhs)
     {
-      FLDTEFD_ fldtefd(getIndxInTefTerms(symb_id, tef_terms), tmpIndx);
+      FLDTEFD_ fldtefd(getIndxInTefTerms(symb_id, tef_terms), inputIndex);
       fldtefd.write(CompileCode, instruction_number);
     }
   else
     {
-      FSTPTEFD_ fstptefd(getIndxInTefTerms(symb_id, tef_terms), tmpIndx);
+      FSTPTEFD_ fstptefd(getIndxInTefTerms(symb_id, tef_terms), inputIndex);
       fstptefd.write(CompileCode, instruction_number);
     }
 }
@@ -5193,16 +5190,11 @@ SecondDerivExternalFunctionNode::writeOutput(ostream &output, ExprNodeOutputType
       return;
     }
 
-  int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
+  const int second_deriv_symb_id = datatree.external_functions_table.getSecondDerivSymbID(symb_id);
   assert(second_deriv_symb_id != eExtFunSetButNoNameProvided);
 
-  int tmpIndex1 = inputIndex1;
-  int tmpIndex2 = inputIndex2;
-  if (IS_C(output_type))
-    {
-      tmpIndex1 = tmpIndex1 - 1;
-      tmpIndex2 = tmpIndex2 - 1;
-    }
+  const int tmpIndex1 = inputIndex1 - ARRAY_SUBSCRIPT_OFFSET(output_type);
+  const int tmpIndex2 = inputIndex2 - ARRAY_SUBSCRIPT_OFFSET(output_type);
 
   int indx = getIndxInTefTerms(symb_id, tef_terms);
   if (second_deriv_symb_id == symb_id)