diff --git a/common/aicore/cm.cpp b/common/aicore/cm.cpp
index 3160135d6c..d9513f856a 100644
--- a/common/aicore/cm.cpp
+++ b/common/aicore/cm.cpp
@@ -1598,20 +1598,21 @@ static void compute_max_stats_heuristic(const struct cm_state *state,
   struct tile *pcenter = city_tile(pcity);
   bool is_celebrating = base_city_celebrating(pcity);
 
-  output_type_iterate(stat_index)
+  city_tile_iterate(city_map_radius_sq_get(pcity), pcenter, ptile)
   {
-    int base = production[stat_index];
-
-    city_tile_iterate(city_map_radius_sq_get(pcity), pcenter, ptile)
+    output_type_iterate(stat_index)
     {
+      int base = production[stat_index];
+
       if (is_free_worked(pcity, ptile)) {
         base += city_tile_output(pcity, ptile, is_celebrating, stat_index);
       }
+
+      pcity->citizen_base[stat_index] = base;
     }
-    city_tile_iterate_end;
-    pcity->citizen_base[stat_index] = base;
+    output_type_iterate_end;
   }
-  output_type_iterate_end;
+  city_tile_iterate_end;
 
   set_city_production(pcity);
   memcpy(production, pcity->prod, sizeof(pcity->prod));