diff --git a/CEP/BB/BBSControl/include/BBSControl/KernelCommandControl.h b/CEP/BB/BBSControl/include/BBSControl/CommandExecutor.h
similarity index 65%
rename from CEP/BB/BBSControl/include/BBSControl/KernelCommandControl.h
rename to CEP/BB/BBSControl/include/BBSControl/CommandExecutor.h
index 1ead413d280414de935de6395c8f262b6de00e09..fc9d088e72c759400da79767844d852bbdcc59f9 100644
--- a/CEP/BB/BBSControl/include/BBSControl/KernelCommandControl.h
+++ b/CEP/BB/BBSControl/include/BBSControl/CommandExecutor.h
@@ -1,4 +1,4 @@
-//# KernelCommandControl.h: 
+//# CommandExecutor.h: 
 //#
 //# Copyright (C) 2007
 //# ASTRON (Netherlands Foundation for Research in Astronomy)
@@ -20,10 +20,10 @@
 //#
 //# $Id$
 
-#ifndef LOFAR_BBSCONTROL_KERNELCOMMANDCONTROL_H
-#define LOFAR_BBSCONTROL_KERNELCOMMANDCONTROL_H
+#ifndef LOFAR_BBSCONTROL_COMMANDEXECUTOR_H
+#define LOFAR_BBSCONTROL_COMMANDEXECUTOR_H
 
-#include <BBSControl/CommandHandler.h>
+#include <BBSControl/CommandVisitor.h>
 #include <BBSControl/BlobStreamableConnection.h>
 //#include <BBSControl/BBSStructs.h>
 
@@ -45,35 +45,33 @@ class Prediffer;
 class RegionOfInterest;
 
 
-class KernelCommandControl: public CommandHandler
+class CommandExecutor: public CommandVisitor
 {
 public:
-    KernelCommandControl(shared_ptr<CommandQueue> &queue,
+    CommandExecutor(shared_ptr<CommandQueue> &queue,
         shared_ptr<BlobStreamableConnection> &solver)
         :   itsCommandQueue(queue),
             itsSolverConnection(solver)
     {
     }
 
-    virtual ~KernelCommandControl()
+    virtual ~CommandExecutor()
     {
     }
 
-    // @name Implementation of handle() for different commands.
+    // @name Implementation of visit() for different commands.
     // @{
-    virtual void handle(const InitializeCommand &command);
-    virtual void handle(const FinalizeCommand &command);
-    virtual void handle(const NextChunkCommand &command);
-    virtual void handle(const BBSStrategy &command);
-    virtual void handle(const BBSStep &command);
-    virtual void handle(const BBSMultiStep &command);
-    virtual void handle(const BBSSingleStep &command);
-    virtual void handle(const BBSPredictStep &command);
-    virtual void handle(const BBSSubtractStep &command);
-    virtual void handle(const BBSCorrectStep &command);
-    virtual void handle(const BBSSolveStep &command);
-    virtual void handle(const BBSShiftStep &command);
-    virtual void handle(const BBSRefitStep &command);
+    virtual void visit(const InitializeCommand &command);
+    virtual void visit(const FinalizeCommand &command);
+    virtual void visit(const NextChunkCommand &command);
+    virtual void visit(const BBSStrategy &command);
+    virtual void visit(const BBSMultiStep &command);
+    virtual void visit(const BBSPredictStep &command);
+    virtual void visit(const BBSSubtractStep &command);
+    virtual void visit(const BBSCorrectStep &command);
+    virtual void visit(const BBSSolveStep &command);
+    virtual void visit(const BBSShiftStep &command);
+    virtual void visit(const BBSRefitStep &command);
     // @}
 
 private:
diff --git a/CEP/BB/BBSControl/include/BBSControl/QueryBuilder/AddCommand.h b/CEP/BB/BBSControl/include/BBSControl/QueryBuilder/AddCommand.h
new file mode 100644
index 0000000000000000000000000000000000000000..e9c4cd0650a0021db1269fbf36d073c297d68401
--- /dev/null
+++ b/CEP/BB/BBSControl/include/BBSControl/QueryBuilder/AddCommand.h
@@ -0,0 +1,106 @@
+//# AddCommand.h: Query builder for adding a command to the command queue.
+//#
+//# Copyright (C) 2007
+//# ASTRON (Netherlands Foundation for Research in Astronomy)
+//# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//#
+//# This program is free software; you can redistribute it and/or modify
+//# it under the terms of the GNU General Public License as published by
+//# the Free Software Foundation; either version 2 of the License, or
+//# (at your option) any later version.
+//#
+//# This program is distributed in the hope that it will be useful,
+//# but WITHOUT ANY WARRANTY; without even the implied warranty of
+//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//# GNU General Public License for more details.
+//#
+//# You should have received a copy of the GNU General Public License
+//# along with this program; if not, write to the Free Software
+//# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//#
+//# $Id$
+
+#ifndef LOFAR_BBSCONTROL_QUERYBUILDER_ADDCOMMAND_H
+#define LOFAR_BBSCONTROL_QUERYBUILDER_ADDCOMMAND_H
+
+// \file 
+// Query builder for adding a command to the command queue.
+
+#include <BBSControl/CommandVisitor.h>
+#include <Common/lofar_string.h>
+#include <Common/lofar_iosfwd.h>
+
+namespace LOFAR
+{
+  namespace BBS
+  {
+    //# Forward declarations
+    class Command;
+    class BBSSingleStep;
+
+    namespace QueryBuilder
+    {
+      // Concrete CommandVisitor class, implements visit() methods for
+      // composing the query to add a concrete Command object to the
+      // CommandQueue. Knowledge about the database structure of the command
+      // queue and its stored procedures are kept within this class.
+      class AddCommand : public CommandVisitor
+      {
+      public:
+        // Destructor.
+        virtual ~AddCommand();
+
+        // @{
+        virtual void visit(const InitializeCommand &command);
+        virtual void visit(const FinalizeCommand &command);
+        virtual void visit(const NextChunkCommand &command);
+        virtual void visit(const BBSStrategy &command);
+        virtual void visit(const BBSMultiStep &command);
+        virtual void visit(const BBSPredictStep &command);
+        virtual void visit(const BBSSubtractStep &command);
+        virtual void visit(const BBSCorrectStep &command);
+        virtual void visit(const BBSSolveStep &command);
+        virtual void visit(const BBSShiftStep &command);
+        virtual void visit(const BBSRefitStep &command);
+        // @}
+
+        // Return the composed query.
+        const string& getQuery() const;
+
+      private:
+        // Return the SELECT clause.
+        // @{
+        string selectClause(const Command& command) const;
+        string selectClause(const BBSStrategy&) const;
+        // @}
+
+        // Start the argument list
+        // @{
+        string beginArgumentList(const Command&) const;
+        string beginArgumentList(const BBSStrategy&) const;
+        // @}
+
+        // End the argument list
+        // @{
+        string endArgumentList(const Command&) const;
+        string endArgumentList(const BBSStrategy&) const;
+        // @}
+
+        // Return the argument list.
+        // @{
+        string argumentList(const BBSStrategy& command) const;
+        string argumentList(const BBSSingleStep& command) const;
+        string argumentList(const BBSSolveStep& command) const;
+        // @}
+
+        // String holding the composed query.
+        string itsQuery;
+      };
+
+    } //# namespace QueryBuilder
+
+  } //# namespace BBS
+
+} //# namespace LOFAR
+
+#endif
diff --git a/CEP/BB/BBSControl/src/KernelCommandControl.cc b/CEP/BB/BBSControl/src/CommandExecutor.cc
similarity index 92%
rename from CEP/BB/BBSControl/src/KernelCommandControl.cc
rename to CEP/BB/BBSControl/src/CommandExecutor.cc
index a17a6d5bb5b925682401252039fb84dc5227f011..bdd70d35339f3406ba7d9c732f4a39402836d2c9 100644
--- a/CEP/BB/BBSControl/src/KernelCommandControl.cc
+++ b/CEP/BB/BBSControl/src/CommandExecutor.cc
@@ -1,4 +1,4 @@
-//# KernelCommandControl.cc: 
+//# CommandExecutor.cc: 
 //#
 //# Copyright (C) 2007
 //# ASTRON (Netherlands Foundation for Research in Astronomy)
@@ -21,7 +21,7 @@
 //# $Id$
 
 #include <lofar_config.h>
-#include <BBSControl/KernelCommandControl.h>
+#include <BBSControl/CommandExecutor.h>
 
 #include <BBSControl/CommandQueue.h>
 #include <BBSControl/BBSStructs.h>
@@ -32,9 +32,7 @@
 #include <BBSControl/IterationResult.h>
 
 #include <BBSControl/BBSStrategy.h>
-#include <BBSControl/BBSStep.h>
 #include <BBSControl/BBSMultiStep.h>
-#include <BBSControl/BBSSingleStep.h>
 #include <BBSControl/BBSPredictStep.h>
 #include <BBSControl/BBSSubtractStep.h>
 #include <BBSControl/BBSCorrectStep.h>
@@ -61,7 +59,7 @@ template class BlobStreamableVector<IterationRequest>;
 template class BlobStreamableVector<IterationResult>;
 
 
-bool KernelCommandControl::convertTime(string in, double &out)
+bool CommandExecutor::convertTime(string in, double &out)
 {
     //# TODO: Convert from default epoch to MS epoch (as it may differ from 
     //# the default!)
@@ -75,7 +73,7 @@ bool KernelCommandControl::convertTime(string in, double &out)
 }
 
 
-void KernelCommandControl::handle(const InitializeCommand &command)
+void CommandExecutor::visit(const InitializeCommand &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -150,7 +148,7 @@ void KernelCommandControl::handle(const InitializeCommand &command)
 }
 
 
-void KernelCommandControl::handle(const FinalizeCommand &command)
+void CommandExecutor::visit(const FinalizeCommand &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -158,7 +156,7 @@ void KernelCommandControl::handle(const FinalizeCommand &command)
 }
 
 
-void KernelCommandControl::handle(const NextChunkCommand &command)
+void CommandExecutor::visit(const NextChunkCommand &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -181,7 +179,7 @@ void KernelCommandControl::handle(const NextChunkCommand &command)
 }
 
 
-void KernelCommandControl::handle(const BBSStrategy &command)
+void CommandExecutor::visit(const BBSStrategy &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -192,28 +190,14 @@ void KernelCommandControl::handle(const BBSStrategy &command)
 }
 
 
-void KernelCommandControl::handle(const BBSStep &command)
-{
-    LOG_DEBUG("Handling a BBSStep");
-    LOG_DEBUG_STR("Command: " << endl << command);
-}
-
-
-void KernelCommandControl::handle(const BBSMultiStep &command)
+void CommandExecutor::visit(const BBSMultiStep &command)
 {
     LOG_DEBUG("Handling a BBSMultiStep");
     LOG_DEBUG_STR("Command: " << endl << command);
 }
 
 
-void KernelCommandControl::handle(const BBSSingleStep &command)
-{
-    LOG_DEBUG("Handling a BBSSingleStep");
-    LOG_DEBUG_STR("Command: " << endl << command);
-}
-
-
-void KernelCommandControl::handle(const BBSPredictStep &command)
+void CommandExecutor::visit(const BBSPredictStep &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -240,7 +224,7 @@ void KernelCommandControl::handle(const BBSPredictStep &command)
 }
 
 
-void KernelCommandControl::handle(const BBSSubtractStep &command)
+void CommandExecutor::visit(const BBSSubtractStep &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -267,7 +251,7 @@ void KernelCommandControl::handle(const BBSSubtractStep &command)
 }
 
 
-void KernelCommandControl::handle(const BBSCorrectStep &command)
+void CommandExecutor::visit(const BBSCorrectStep &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -294,7 +278,7 @@ void KernelCommandControl::handle(const BBSCorrectStep &command)
 }
 
 
-void KernelCommandControl::handle(const BBSSolveStep &command)
+void CommandExecutor::visit(const BBSSolveStep &command)
 {
     LOG_TRACE_FLOW(AUTO_FUNCTION_NAME);
 
@@ -517,14 +501,14 @@ void KernelCommandControl::handle(const BBSSolveStep &command)
 }
 
 
-void KernelCommandControl::handle(const BBSShiftStep &command)
+void CommandExecutor::visit(const BBSShiftStep &command)
 {
     LOG_DEBUG("Handling a BBSShiftStep");
     LOG_DEBUG_STR("Command: " << endl << command);
 }
 
 
-void KernelCommandControl::handle(const BBSRefitStep &command)
+void CommandExecutor::visit(const BBSRefitStep &command)
 {
     LOG_DEBUG("Handling a BBSRefitStep");
     LOG_DEBUG_STR("Command: " << endl << command);
diff --git a/CEP/BB/BBSControl/src/QueryBuilder/AddCommand.cc b/CEP/BB/BBSControl/src/QueryBuilder/AddCommand.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2acf64d9828bbac3c2a451c3409f35e2db122ca7
--- /dev/null
+++ b/CEP/BB/BBSControl/src/QueryBuilder/AddCommand.cc
@@ -0,0 +1,263 @@
+//#  AddCommand.cc: one line description
+//#
+//#  Copyright (C) 2002-2004
+//#  ASTRON (Netherlands Foundation for Research in Astronomy)
+//#  P.O.Box 2, 7990 AA Dwingeloo, The Netherlands, seg@astron.nl
+//#
+//#  This program is free software; you can redistribute it and/or modify
+//#  it under the terms of the GNU General Public License as published by
+//#  the Free Software Foundation; either version 2 of the License, or
+//#  (at your option) any later version.
+//#
+//#  This program is distributed in the hope that it will be useful,
+//#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//#  GNU General Public License for more details.
+//#
+//#  You should have received a copy of the GNU General Public License
+//#  along with this program; if not, write to the Free Software
+//#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+//#
+//#  $Id$
+
+//# Always #include <lofar_config.h> first!
+#include <lofar_config.h>
+
+//# Includes
+#include <BBSControl/QueryBuilder/AddCommand.h>
+#include <BBSControl/InitializeCommand.h>
+#include <BBSControl/FinalizeCommand.h>
+#include <BBSControl/NextChunkCommand.h>
+#include <BBSControl/BBSStrategy.h>
+#include <BBSControl/BBSMultiStep.h>
+#include <BBSControl/BBSPredictStep.h>
+#include <BBSControl/BBSSubtractStep.h>
+#include <BBSControl/BBSCorrectStep.h>
+#include <BBSControl/BBSSolveStep.h>
+#include <BBSControl/BBSShiftStep.h>
+#include <BBSControl/BBSRefitStep.h>
+#include <BBSControl/Exceptions.h>
+#include <Common/LofarLogger.h>
+
+namespace LOFAR
+{
+  namespace BBS
+  {
+    using LOFAR::operator<<;
+
+    namespace QueryBuilder
+    {
+
+      //##--------   P u b l i c   m e t h o d s   --------##//
+
+      AddCommand::~AddCommand()
+      {
+      }
+
+
+      void AddCommand::visit(const InitializeCommand &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+      }
+
+
+      void AddCommand::visit(const FinalizeCommand &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+      }
+
+
+      void AddCommand::visit(const NextChunkCommand &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+      }
+
+
+      void AddCommand::visit(const BBSStrategy &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        itsQuery = 
+          selectClause(command) + 
+          beginArgumentList(command)   +
+          argumentList(command) +
+          endArgumentList(command);
+      }
+
+
+      void AddCommand::visit(const BBSMultiStep &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        THROW (CommandQueueException, 
+               command.type() << " cannot be added to the command queue.");
+      }
+
+
+      void AddCommand::visit(const BBSPredictStep &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        itsQuery = 
+          selectClause(command) + 
+          beginArgumentList(command)   +
+          argumentList(command) +
+          endArgumentList(command);
+      }
+
+
+      void AddCommand::visit(const BBSSubtractStep &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        itsQuery = 
+          selectClause(command) + 
+          beginArgumentList(command)   +
+          argumentList(command) +
+          endArgumentList(command);
+      }
+
+
+      void AddCommand::visit(const BBSCorrectStep &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        itsQuery = 
+          selectClause(command) + 
+          beginArgumentList(command)   +
+          argumentList(command) +
+          endArgumentList(command);
+      }
+
+
+      void AddCommand::visit(const BBSSolveStep &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        itsQuery = 
+          selectClause(command) + 
+          beginArgumentList(command)   +
+          argumentList(command) +
+          endArgumentList(command);
+      }
+
+
+      void AddCommand::visit(const BBSShiftStep &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        itsQuery = 
+          selectClause(command) + 
+          beginArgumentList(command)   +
+          argumentList(command) +
+          endArgumentList(command);
+      }
+
+
+      void AddCommand::visit(const BBSRefitStep &command)
+      {
+        LOG_TRACE_LIFETIME_STR(TRACE_LEVEL_COND, command.type());
+        itsQuery = 
+          selectClause(command) + 
+          beginArgumentList(command)   +
+          argumentList(command) +
+          endArgumentList(command);
+      }
+
+
+      const string& AddCommand::getQuery() const
+      {
+        return itsQuery;
+      }
+
+
+      //##--------   P r i v a t e   m e t h o d s   --------##//
+
+      string AddCommand::selectClause(const Command& command) const
+      {
+        return 
+          "SELECT * FROM blackboard.add_" + 
+          toLower(command.type())         +
+          "_command";
+      }
+
+
+      string AddCommand::selectClause(const BBSStrategy&) const
+      {
+        return "SELECT * FROM blackboard.set_strategy";
+      }
+
+
+      string AddCommand::beginArgumentList(const Command&) const
+      {
+        return "(ROW(";
+      }
+
+
+      string AddCommand::endArgumentList(const Command&) const
+      {
+        return "))";
+      }
+
+
+      string AddCommand::beginArgumentList(const BBSStrategy&) const
+      {
+        return "(";
+      }
+
+
+      string AddCommand::endArgumentList(const BBSStrategy&) const
+      {
+        return ") AS result";
+      }
+
+
+      string AddCommand::argumentList(const BBSStrategy& strategy) const
+      {
+        ostringstream oss;
+        oss << "'"  << strategy.dataSet()                    << "'"
+            << ",'" << strategy.parmDB().localSky            << "'"
+            << ",'" << strategy.parmDB().instrument          << "'"
+            << ",'" << strategy.parmDB().history             << "'"
+            << ",'" << strategy.stations()                   << "'"
+            << ",'" << strategy.inputData()                  << "'"
+            << ",'" << strategy.regionOfInterest().frequency << "'"
+            << ",'" << strategy.regionOfInterest().time      << "'"
+            << ",'" << strategy.domainSize().bandWidth       << "'"
+            << ",'" << strategy.domainSize().timeInterval    << "'"
+            << ",'" << strategy.correlation().selection      << "'"
+            << ",'" << strategy.correlation().type           << "'";
+        return oss.str();
+      }
+
+
+      string AddCommand::argumentList(const BBSSingleStep& step) const
+      {
+        ostringstream oss;
+        oss << "'"  << step.getName()               << "'"
+            << ",'" << step.operation()             << "'"
+            << ",'" << step.baselines().station1    << "'"
+            << ",'" << step.baselines().station2    << "'"
+            << ",'" << step.correlation().selection << "'"
+            << ",'" << step.correlation().type      << "'"
+            << ",'" << step.sources()               << "'"
+            << ",'" << step.instrumentModels()      << "'"
+            << ",'" << step.outputData()            << "'";
+
+        return oss.str();
+      }
+
+
+      string AddCommand::argumentList(const BBSSolveStep& step) const
+      {
+        ostringstream oss;
+        oss << argumentList(static_cast<const BBSSingleStep&>(step)) 
+            << ",'" << step.maxIter()                  << "'"
+            << ",'" << step.epsilon()                  << "'"
+            << ",'" << step.minConverged()             << "'"
+            << ",'" << step.parms()                    << "'"
+            << ",'" << step.exclParms()                << "'"
+            << ",'" << step.domainSize().bandWidth     << "'"
+            << ",'" << step.domainSize().timeInterval  << "'";
+        return oss.str();
+      }
+
+
+    } // namespace QueryBuilder
+
+  } // namespace BBS
+
+} // namespace LOFAR