diff --git a/mex/sources/k_order_perturbation/k_order_perturbation.cc b/mex/sources/k_order_perturbation/k_order_perturbation.cc
index 1159b810bf98b6f1441b0f29d1a9d55692b5c1a3..1e6a88cc0da566aa02235066c7ccda0e40ebe14a 100644
--- a/mex/sources/k_order_perturbation/k_order_perturbation.cc
+++ b/mex/sources/k_order_perturbation/k_order_perturbation.cc
@@ -293,7 +293,7 @@ extern "C" {
                 ++ii;
 
               }
-            if (kOrder == 3 && nlhs > 4)
+            if (kOrder == 3 && nlhs > 5)
               {
                 const FGSContainer *derivs = app.get_rule_ders();
                 const std::string fieldnames[] = {"gy", "gu", "gyy", "gyu", "guu", "gss",