diff --git a/pymola/backends/casadi/api.py b/pymola/backends/casadi/api.py
index <HASH>..<HASH> 100644
--- a/pymola/backends/casadi/api.py
+++ b/pymola/backends/casadi/api.py
@@ -125,16 +125,11 @@ def _save_model(model_folder: str, model_name: str, model: Model):
         library_name = '{}_{}'.format(model_name, o)
 
         cg = ca.CodeGenerator(library_name)
-
-        # Create temporary variables to keep the functions in scope
-        # cfr casadi bug #2059
-        fr = f.reverse(1)
-        ff = f.forward(1)
-        frf = fr.forward(1)
-        cg.add(f)
-        cg.add(ff)
-        cg.add(fr)
-        cg.add(frf)
+        cg.add(f) # Nondifferentiated function
+        cg.add(f.forward(1)) # Jacobian-times-vector product
+        cg.add(f.reverse(1)) # vector-times-Jacobian product
+        cg.add(f.reverse(1).forward(1)) # Hessian-times-vector product
+        cg.add(f.jacobian()) # Jacobian
         cg.generate(model_folder + '/')
 
         compiler = distutils.ccompiler.new_compiler()
Included Jacobian information in generated code
Note that this commit requires CasADi at revision <I>fd4c or newer (Sep <I>, <I>)