diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGenerator.ui b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGenerator.ui
index 79c352243ca3dcc08fd4000d676627ef3ecfa4aa..73b14e379429da54ad8b46a9333c6b84b857095d 100644
--- a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGenerator.ui
+++ b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGenerator.ui
@@ -148,13 +148,13 @@
            <widget class="QPushButton" name="pbSelectedDomains">
             <property name="minimumSize">
              <size>
-              <width>98</width>
+              <width>100</width>
               <height>0</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
-              <width>98</width>
+              <width>100</width>
               <height>16777215</height>
              </size>
             </property>
@@ -170,13 +170,13 @@
            <widget class="QPushButton" name="pbAllDomains">
             <property name="minimumSize">
              <size>
-              <width>98</width>
+              <width>100</width>
               <height>0</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
-              <width>98</width>
+              <width>100</width>
               <height>16777215</height>
              </size>
             </property>
diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorDataTable.h b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorDataTable.h
index c0ad418b66b99f31b906bb09d6ff6898761ec4f1..1f74616a2f40dfe3afc1c242399c256210670ae1 100644
--- a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorDataTable.h
+++ b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorDataTable.h
@@ -58,6 +58,8 @@ public:
   [[nodiscard]] std::vector<FitDomainIndex> allRows() const;
   [[nodiscard]] std::vector<FitDomainIndex> selectedRows() const;
 
+  bool hasLoadedData() const;
+
   [[nodiscard]] QString selectedDomainFunctionPrefix() const;
 
   void removeDomain(std::string const &workspaceName,
diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h
index 4788a7eb323514da1b8ea85549e1bdaca98207b8..c5cfca0d43ee68ef813e247a6613826341bd298f 100644
--- a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h
+++ b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorPresenter.h
@@ -86,14 +86,6 @@ private:
   void updateEndX(std::string const &workspaceName,
                   WorkspaceIndex workspaceIndex, double endX);
 
-  void
-  removeFunctionForDomains(std::string const &function,
-                           std::vector<FitDomainIndex> const &domainIndices);
-  void addFunctionForDomains(std::string const &function,
-                             std::vector<FitDomainIndex> const &domainIndices);
-  void setFunctionForDomains(std::string const &function,
-                             std::vector<FitDomainIndex> const &domainIndices);
-
   void updateParameterTie(std::string const &workspaceName,
                           WorkspaceIndex workspaceIndex,
                           std::string const &parameter, std::string const &tie);
@@ -102,6 +94,11 @@ private:
 
   void checkForWarningMessages();
 
+  template <void (IFitScriptGeneratorModel::*func)(
+      std::string const &workspaceName, WorkspaceIndex workspaceIndex,
+      std::string const &function)>
+  void updateDomainFunctions(std::string const &function);
+
   std::vector<std::string> m_warnings;
 
   IFitScriptGeneratorView *m_view;
diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h
index 9bc41e3033f8212223018655f9b21da4175b9cd9..017bcac298141c0d57f50ab4ebd8913ce0469d65 100644
--- a/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h
+++ b/qt/widgets/common/inc/MantidQtWidgets/Common/FitScriptGeneratorView.h
@@ -57,6 +57,8 @@ public:
   [[nodiscard]] std::vector<FitDomainIndex> allRows() const override;
   [[nodiscard]] std::vector<FitDomainIndex> selectedRows() const override;
 
+  [[nodiscard]] bool hasLoadedData() const override;
+
   [[nodiscard]] double
   parameterValue(std::string const &parameter) const override;
   [[nodiscard]] Mantid::API::IFunction::Attribute
diff --git a/qt/widgets/common/inc/MantidQtWidgets/Common/IFitScriptGeneratorView.h b/qt/widgets/common/inc/MantidQtWidgets/Common/IFitScriptGeneratorView.h
index e8f478bf31e6ef442d348df3df2758afbc228f71..1755972e3d666c048e51c6a79abb458e8546d616 100644
--- a/qt/widgets/common/inc/MantidQtWidgets/Common/IFitScriptGeneratorView.h
+++ b/qt/widgets/common/inc/MantidQtWidgets/Common/IFitScriptGeneratorView.h
@@ -69,6 +69,8 @@ public:
   [[nodiscard]] virtual std::vector<FitDomainIndex> allRows() const = 0;
   [[nodiscard]] virtual std::vector<FitDomainIndex> selectedRows() const = 0;
 
+  [[nodiscard]] virtual bool hasLoadedData() const = 0;
+
   [[nodiscard]] virtual double
   parameterValue(std::string const &parameter) const = 0;
   [[nodiscard]] virtual Mantid::API::IFunction::Attribute
diff --git a/qt/widgets/common/src/FitScriptGeneratorDataTable.cpp b/qt/widgets/common/src/FitScriptGeneratorDataTable.cpp
index 1c487b7b33bf052b5d903a14e9894c2c6dff6313..2a45726e82044b2f17e31dade2c398a64b05f47f 100644
--- a/qt/widgets/common/src/FitScriptGeneratorDataTable.cpp
+++ b/qt/widgets/common/src/FitScriptGeneratorDataTable.cpp
@@ -229,6 +229,10 @@ std::vector<FitDomainIndex> FitScriptGeneratorDataTable::selectedRows() const {
   return rowIndices;
 }
 
+bool FitScriptGeneratorDataTable::hasLoadedData() const {
+  return this->rowCount() > 0;
+}
+
 QString FitScriptGeneratorDataTable::selectedDomainFunctionPrefix() const {
   auto const rows = selectedRows();
   if (rows.empty())
diff --git a/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp b/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp
index f6164d20a1cf9c0a5b612f6b5ce131cf24d75c40..bbaead62b87ad68c1a81094b042983422c555ec6 100644
--- a/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp
+++ b/qt/widgets/common/src/FitScriptGeneratorPresenter.cpp
@@ -175,37 +175,30 @@ void FitScriptGeneratorPresenter::handleSelectionChanged() {
 
 void FitScriptGeneratorPresenter::handleFunctionRemoved(
     std::string const &function) {
-  auto const rowIndices = getRowIndices();
-
-  if (!rowIndices.empty()) {
-    removeFunctionForDomains(function, rowIndices);
+  if (m_view->hasLoadedData()) {
+    updateDomainFunctions<&IFitScriptGeneratorModel::removeFunction>(function);
     handleSelectionChanged();
   }
 }
 
 void FitScriptGeneratorPresenter::handleFunctionAdded(
     std::string const &function) {
-  auto const rowIndices = getRowIndices();
-
-  if (rowIndices.empty()) {
+  if (m_view->hasLoadedData()) {
+    try {
+      updateDomainFunctions<&IFitScriptGeneratorModel::addFunction>(function);
+    } catch (std::invalid_argument const &ex) {
+      m_view->displayWarning(ex.what());
+    }
+  } else {
     m_view->displayWarning("Data needs to be loaded before adding a function.");
     m_view->clearFunction();
-    return;
-  }
-
-  try {
-    addFunctionForDomains(function, rowIndices);
-  } catch (std::invalid_argument const &ex) {
-    m_view->displayWarning(ex.what());
   }
 }
 
 void FitScriptGeneratorPresenter::handleFunctionReplaced(
     std::string const &function) {
-  auto const rowIndices = getRowIndices();
-
-  if (!rowIndices.empty()) {
-    setFunctionForDomains(function, rowIndices);
+  if (m_view->hasLoadedData()) {
+    updateDomainFunctions<&IFitScriptGeneratorModel::setFunction>(function);
   } else {
     m_view->displayWarning("Data needs to be loaded before adding a function.");
     m_view->clearFunction();
@@ -375,33 +368,15 @@ void FitScriptGeneratorPresenter::updateEndX(std::string const &workspaceName,
   }
 }
 
-void FitScriptGeneratorPresenter::removeFunctionForDomains(
-    std::string const &function,
-    std::vector<FitDomainIndex> const &domainIndices) {
-  for (auto const &domainIndex : domainIndices) {
-    auto const workspaceName = m_view->workspaceName(domainIndex);
-    auto const workspaceIndex = m_view->workspaceIndex(domainIndex);
-    m_model->removeFunction(workspaceName, workspaceIndex, function);
-  }
-}
-
-void FitScriptGeneratorPresenter::addFunctionForDomains(
-    std::string const &function,
-    std::vector<FitDomainIndex> const &domainIndices) {
-  for (auto const &domainIndex : domainIndices) {
-    auto const workspaceName = m_view->workspaceName(domainIndex);
-    auto const workspaceIndex = m_view->workspaceIndex(domainIndex);
-    m_model->addFunction(workspaceName, workspaceIndex, function);
-  }
-}
-
-void FitScriptGeneratorPresenter::setFunctionForDomains(
-    std::string const &function,
-    std::vector<FitDomainIndex> const &domainIndices) {
-  for (auto const &domainIndex : domainIndices) {
+template <void (IFitScriptGeneratorModel::*func)(
+    std::string const &workspaceName, WorkspaceIndex workspaceIndex,
+    std::string const &function)>
+void FitScriptGeneratorPresenter::updateDomainFunctions(
+    std::string const &function) {
+  for (auto const &domainIndex : getRowIndices()) {
     auto const workspaceName = m_view->workspaceName(domainIndex);
     auto const workspaceIndex = m_view->workspaceIndex(domainIndex);
-    m_model->setFunction(workspaceName, workspaceIndex, function);
+    (m_model->*func)(workspaceName, workspaceIndex, function);
   }
 }
 
diff --git a/qt/widgets/common/src/FitScriptGeneratorView.cpp b/qt/widgets/common/src/FitScriptGeneratorView.cpp
index 42939aae72312d6adb13b72ef2107fab59ca1652..ab7ef6d81198f142a7ad2cd9227b072f30a532d8 100644
--- a/qt/widgets/common/src/FitScriptGeneratorView.cpp
+++ b/qt/widgets/common/src/FitScriptGeneratorView.cpp
@@ -293,6 +293,10 @@ std::vector<FitDomainIndex> FitScriptGeneratorView::selectedRows() const {
   return m_dataTable->selectedRows();
 }
 
+bool FitScriptGeneratorView::hasLoadedData() const {
+  return m_dataTable->hasLoadedData();
+}
+
 double
 FitScriptGeneratorView::parameterValue(std::string const &parameter) const {
   return m_functionTreeView->getParameter(QString::fromStdString(parameter));