diff --git a/src/EquationTags.cc b/src/EquationTags.cc
index c547378053fbe43772c75f51a4fc1b36a5d3928c..c55fff0eed2357be86a6fdec356a3a589cbb64b0 100644
--- a/src/EquationTags.cc
+++ b/src/EquationTags.cc
@@ -21,6 +21,7 @@
 
 #include <regex>
 #include <ostream>
+#include <utility>
 
 set<int>
 EquationTags::getEqnsByKey(const string &key) const
@@ -93,51 +94,46 @@ EquationTags::writeLatexOutput(ostream &output, int eqn) const
   if (!exists(eqn))
     return;
 
-  auto escape_special_latex_symbols
-    = [](string str)
-      {
-        const regex special_latex_chars (R"([&%$#_{}])");
-        const regex backslash (R"(\\)");
-        const regex tilde (R"(~)");
-        const regex carrot (R"(\^)");
-        const regex textbackslash (R"(\\textbackslash)");
-        str = regex_replace(str, backslash, R"(\textbackslash)");
-        str = regex_replace(str, special_latex_chars, R"(\$&)");
-        str = regex_replace(str, carrot, R"(\^{})");
-        str = regex_replace(str, tilde, R"(\textasciitilde{})");
-        return regex_replace(str, textbackslash, R"(\textbackslash{})");
-      };
+  auto escape_special_latex_symbols = [](string str)
+  {
+    const regex special_latex_chars (R"([&%$#_{}])");
+    const regex backslash (R"(\\)");
+    const regex tilde (R"(~)");
+    const regex carrot (R"(\^)");
+    const regex textbackslash (R"(\\textbackslash)");
+    str = regex_replace(str, backslash, R"(\textbackslash)");
+    str = regex_replace(str, special_latex_chars, R"(\$&)");
+    str = regex_replace(str, carrot, R"(\^{})");
+    str = regex_replace(str, tilde, R"(\textasciitilde{})");
+    return regex_replace(str, textbackslash, R"(\textbackslash{})");
+  };
 
-  bool wrote_eq_tag = false;
   output << R"(\noindent[)";
-  for (const auto & [key, value] : eqn_tags.at(eqn))
+  for (bool wrote_eq_tag {false};
+       const auto & [key, value] : eqn_tags.at(eqn))
     {
-      if (wrote_eq_tag)
+      if (exchange(wrote_eq_tag, true))
         output << ", ";
       output << escape_special_latex_symbols(key);
 
       if (!value.empty())
         output << "= `" << escape_special_latex_symbols(value) << "'";
-
-      wrote_eq_tag = true;
     }
   output << "]" << endl;
 }
 
 void
-EquationTags::writeJsonAST(ostream &output, const int eqn) const
+EquationTags::writeJsonAST(ostream &output, int eqn) const
 {
   if (!exists(eqn))
     return;
 
   output << R"(, "tags": {)";
-  bool wroteFirst = false;
-  for (const auto &[key, value] : eqn_tags.at(eqn))
+  for (bool wroteFirst {false};
+       const auto &[key, value] : eqn_tags.at(eqn))
     {
-      if (wroteFirst)
+      if (exchange(wroteFirst, true))
         output << ", ";
-      else
-        wroteFirst = true;
       output << R"(")" << key << R"(": ")" << value << R"(")";
     }
   output << "}";
diff --git a/src/EquationTags.hh b/src/EquationTags.hh
index 85dcc5f8bc42a10d7aa3814c65e7ca22fb401a5c..1eb74a8b03e13b97427e26d8aafa6b026b29ddfc 100644
--- a/src/EquationTags.hh
+++ b/src/EquationTags.hh
@@ -63,11 +63,11 @@ public:
   //! Various functions to get info from equation tags
   //! Get equation tags for a given equation
   map<string, string>
-  getTagsByEqn(const int eqn) const
+  getTagsByEqn(int eqn) const
   {
     if (auto it = eqn_tags.find(eqn); it != eqn_tags.end())
       return it->second;
-    return map<string, string>{};
+    return {};
   }
 
   //! Get equations that have the given key
@@ -104,23 +104,24 @@ public:
   }
 
   bool
-  exists(const int eqn) const
+  exists(int eqn) const
   {
     return eqn_tags.contains(eqn);
   }
 
   //! Returns true if equation tag with key exists for a given equation
   bool
-  exists(const int eqn, const string &key) const
+  exists(int eqn, const string &key) const
   {
-    return exists(eqn) && eqn_tags.at(eqn).contains(key);
+    auto it = eqn_tags.find(eqn);
+    return it != eqn_tags.end() && it->second.contains(key);
   }
 
   //! Various functions to write equation tags
   void writeCheckSumInfo(ostream &output) const;
   void writeOutput(ostream &output) const;
   void writeLatexOutput(ostream &output, int eqn) const;
-  void writeJsonAST(ostream &output, const int eq) const;
+  void writeJsonAST(ostream &output, int eq) const;
 };
 
 #endif