diff --git a/src/ExprNode.cc b/src/ExprNode.cc
index 105a9b606ffd0741efba849600468c48e6b9adac..f598b5dba94fe198106468e06f5444b59e52a4ea 100644
--- a/src/ExprNode.cc
+++ b/src/ExprNode.cc
@@ -121,7 +121,7 @@ ExprNode::checkIfTemporaryTermThenWrite(ostream &output, ExprNodeOutputType outp
         // It is the responsibility of the caller to ensure that all temporary terms have their index
         assert(it2 != temporary_terms_idxs.end());
         output << "T" << LEFT_ARRAY_SUBSCRIPT(output_type)
-               << it2->second
+               << it2->second + ARRAY_SUBSCRIPT_OFFSET(output_type)
                << RIGHT_ARRAY_SUBSCRIPT(output_type);
       }
   return true;
diff --git a/src/ModelTree.cc b/src/ModelTree.cc
index c3045139dd4410268e75c0deeb7bc531d696a8b8..998ae76e99742bc47b8497e1bf0029a0b934a03f 100644
--- a/src/ModelTree.cc
+++ b/src/ModelTree.cc
@@ -1179,7 +1179,7 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
   temporary_terms_g2  = temp_terms_map[eSecondDeriv];
   temporary_terms_g3  = temp_terms_map[eThirdDeriv];
 
-  int idx = 1;
+  int idx = 0;
   for (map<expr_t, expr_t>::const_iterator it = temporary_terms_mlv.begin();
        it != temporary_terms_mlv.end(); it++)
     temporary_terms_idxs[it->first] = idx++;