diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc
index 3a4162f2d71325ddd2cb8ba466a1845805209046..398c22e76952755957694c033ab0ce5ea1613e72 100644
--- a/src/DynamicModel.cc
+++ b/src/DynamicModel.cc
@@ -731,9 +731,9 @@ DynamicModel::removeEquationsHelper(
       }
   int n_excl = all_equations.size() - new_equations.size();
 
-  all_equations = new_equations;
-  all_equations_lineno = new_equations_lineno;
-  all_complementarity_conditions = new_complementarity_conditions;
+  all_equations = move(new_equations);
+  all_equations_lineno = move(new_equations_lineno);
+  all_complementarity_conditions = move(new_complementarity_conditions);
 
   all_equation_tags.erase(eqs_to_delete_by_number, old_eqn_num_2_new);
 
diff --git a/src/EquationTags.cc b/src/EquationTags.cc
index db8e1c2ed129827ea37308f4c802e1371113e17d..a446610f6b453cf7db9cba9e5b025567a05df8e1 100644
--- a/src/EquationTags.cc
+++ b/src/EquationTags.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2020-2023 Dynare Team
+ * Copyright © 2020-2025 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -74,13 +74,12 @@ EquationTags::erase(const set<int>& eqns, const map<int, int>& old_eqn_num_2_new
     eqn_tags.erase(eqn);
 
   for (const auto& [oldeqn, neweqn] : old_eqn_num_2_new)
-    for (auto& [eqn, tags] : eqn_tags)
-      if (eqn == oldeqn)
-        {
-          auto tmp = eqn_tags.extract(eqn);
-          tmp.key() = neweqn;
-          eqn_tags.insert(move(tmp));
-        }
+    if (eqn_tags.contains(oldeqn))
+      {
+        auto tmp = eqn_tags.extract(oldeqn);
+        tmp.key() = neweqn;
+        eqn_tags.insert(move(tmp));
+      }
 }
 
 void