diff --git a/src/PlumedMain.cpp b/src/PlumedMain.cpp
index 3b7bcd4bedb3a7bfc1fb78b99979cdba74781c22..e3267f097ce0f1382e883dc734f1cf4bee3ad700 100644
--- a/src/PlumedMain.cpp
+++ b/src/PlumedMain.cpp
@@ -73,13 +73,17 @@ static class PlumedMainInitializer{
 
 PlumedMain::PlumedMain():
   initialized(false),
+  grex(NULL),
   log(comm),
   step(0),
   active(false),
   atoms(*this),
   actionSet((*this)),
   novirial(false)
-{
+{}
+
+PlumedMain::~PlumedMain(){
+  if(grex) delete grex;
 }
 
 /////////////////////////////////////////////////////////////
@@ -259,6 +263,9 @@ void PlumedMain::cmd(const std::string & word,void*val){
        int check=0;
        if(actionRegister().check(words[1])) check=1;
        *(static_cast<int*>(val))=check;
+     } else if(nw==2 && words[0]=="GREX"){
+       assert(grex);
+       grex->cmd(words[1],val);
      } else{
    // error
        fprintf(stderr,"+++ PLUMED ERROR\n");
diff --git a/src/PlumedMain.h b/src/PlumedMain.h
index 0b4a3835aa33ccf25321fddcf8ac90719a7b8fec..060800e18c20fc815e631a9192de7f9e9b1a9b2b 100644
--- a/src/PlumedMain.h
+++ b/src/PlumedMain.h
@@ -47,6 +47,7 @@ public:
   PlumedCommunicator comm;
 
 private:
+  WithCmd* grex;
 /// Flag to avoid double initialization
   bool  initialized;
 /// Name of MD engine
@@ -91,7 +92,7 @@ public:
 /// and an MD engine, this is the right place
 /// Notice that this interface should always keep retro-compatibility
   void cmd(const std::string&key,void*val=NULL);
-  ~PlumedMain(){};
+  ~PlumedMain();
 /// Read an input file.
 /// \param str name of the file
   void readInputFile(std::string str);