diff --git a/src/core/CLToolMain.cpp b/src/core/CLToolMain.cpp
index d595ebc77e13863277badc9b1bc644dfc84ac6c2..ef53aa9c521a97f4a4a71e22665bcb4196252f26 100644
--- a/src/core/CLToolMain.cpp
+++ b/src/core/CLToolMain.cpp
@@ -37,20 +37,8 @@
 
 using namespace std;
 
-#include "CLToolMainEnum.inc"
-
 namespace PLMD {
 
-const std::unordered_map<std::string, int> & clToolMainWordMap() {
-  static std::unordered_map<std::string, int> word_map;
-  static bool init=false;
-  if(!init) {
-#include "CLToolMainMap.inc"
-  }
-  init=true;
-  return word_map;
-}
-
 CLToolMain::CLToolMain():
   argc(0),
   in(stdin),
@@ -66,6 +54,16 @@ CLToolMain::~CLToolMain() {
 
 void CLToolMain::cmd(const std::string& word,void*val) {
 
+// Enumerate all possible commands:
+  enum {
+#include "CLToolMainEnum.inc"
+  };
+
+// Static object (initialized once) containing the map of commands:
+  const static std::unordered_map<std::string, int> word_map = {
+#include "CLToolMainMap.inc"
+  };
+
   std::vector<std::string> words=Tools::getWords(word);
   unsigned nw=words.size();
   if(nw==0) {
@@ -74,8 +72,8 @@ void CLToolMain::cmd(const std::string& word,void*val) {
     int iword=-1;
     char**v;
     char*vv;
-    const auto it=clToolMainWordMap().find(words[0]);
-    if(it!=clToolMainWordMap().end()) iword=it->second;
+    const auto it=word_map.find(words[0]);
+    if(it!=word_map.end()) iword=it->second;
     switch(iword) {
     case cmd_setArgc:
       CHECK_NULL(val,word);
diff --git a/src/core/GREX.cpp b/src/core/GREX.cpp
index b2510d0c6e060d60bcdee11f63d52e27b2f5d5af..59b4112faedcfc6dc8c895037d2528f0996e845e 100644
--- a/src/core/GREX.cpp
+++ b/src/core/GREX.cpp
@@ -27,21 +27,9 @@
 #include <sstream>
 #include <unordered_map>
 
-#include "GREXEnum.inc"
-
 using namespace std;
 namespace PLMD {
 
-const std::unordered_map<std::string, int> & GREXWordMap() {
-  static std::unordered_map<std::string, int> word_map;
-  static bool init=false;
-  if(!init) {
-#include "GREXMap.inc"
-  }
-  init=true;
-  return word_map;
-}
-
 GREX::GREX(PlumedMain&p):
   initialized(false),
   plumedMain(p),
@@ -65,14 +53,25 @@ GREX::~GREX() {
 #define CHECK_NOTNULL(val,word) plumed_massert(val,"NULL pointer received in cmd(\"GREX " + word + "\")");
 
 void GREX::cmd(const string&key,void*val) {
+
+// Enumerate all possible commands:
+  enum {
+#include "GREXEnum.inc"
+  };
+
+// Static object (initialized once) containing the map of commands:
+  const static std::unordered_map<std::string, int> word_map = {
+#include "GREXMap.inc"
+  };
+
   std::vector<std::string> words=Tools::getWords(key);
   unsigned nw=words.size();
   if(nw==0) {
     // do nothing
   } else {
     int iword=-1;
-    const auto it=GREXWordMap().find(words[0]);
-    if(it!=GREXWordMap().end()) iword=it->second;
+    const auto it=word_map.find(words[0]);
+    if(it!=word_map.end()) iword=it->second;
     switch(iword) {
     case cmd_initialized:
       CHECK_NOTNULL(val,key);
diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp
index 4c4f8e0268b5e456e83a4b15df5faacd29526b06..781a80262566741eb2d1470f037bfc9a3d2322ff 100644
--- a/src/core/PlumedMain.cpp
+++ b/src/core/PlumedMain.cpp
@@ -48,20 +48,8 @@
 
 using namespace std;
 
-#include "PlumedMainEnum.inc"
-
 namespace PLMD {
 
-const std::unordered_map<std::string, int> & plumedMainWordMap() {
-  static std::unordered_map<std::string, int> word_map;
-  static bool init=false;
-  if(!init) {
-#include "PlumedMainMap.inc"
-  }
-  init=true;
-  return word_map;
-}
-
 PlumedMain::PlumedMain():
   initialized(false),
 // automatically write on log in destructor
@@ -100,6 +88,16 @@ PlumedMain::~PlumedMain() {
 
 void PlumedMain::cmd(const std::string & word,void*val) {
 
+// Enumerate all possible commands:
+  enum {
+#include "PlumedMainEnum.inc"
+  };
+
+// Static object (initialized once) containing the map of commands:
+  const static std::unordered_map<std::string, int> word_map = {
+#include "PlumedMainMap.inc"
+  };
+
   try {
 
     auto ss=stopwatch.startPause();
@@ -111,8 +109,8 @@ void PlumedMain::cmd(const std::string & word,void*val) {
     } else {
       int iword=-1;
       double d;
-      const auto it=plumedMainWordMap().find(words[0]);
-      if(it!=plumedMainWordMap().end()) iword=it->second;
+      const auto it=word_map.find(words[0]);
+      if(it!=word_map.end()) iword=it->second;
       switch(iword) {
       case cmd_setBox:
         CHECK_INIT(initialized,word);
diff --git a/src/maketools/makecmd b/src/maketools/makecmd
index e469dffb2dfcd19519df3c712d7923639a451ecf..cb6550c40a2efc20f71815c0428074de0844c3b3 100755
--- a/src/maketools/makecmd
+++ b/src/maketools/makecmd
@@ -13,15 +13,17 @@ awk -v opt=$1 '
   }END{
   n=i;
   if(opt=="enum"){
-    print "enum {"
     for(i=1;i<=n;i++){
-      comma=","
-      if(i==n) comma=""
-      print enum[i],comma;
+      comma=",";
+      if(i==n) comma="";
+      printf("%s%s\n",enum[i],comma);
     }
-    print "};"
   } else if(opt=="map"){
-    for(i=1;i<=n;i++) printf("  word_map[\"%s\"]=%s;\n",string[i],enum[i]);
+    for(i=1;i<=n;i++) {
+      comma=",";
+      if(i==n) comma="";
+      printf("  {\"%s\",%s}%s\n",string[i],enum[i],comma);
+    }
   }
   }'