diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/AlignAndFocusPowder.h b/Code/Mantid/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/AlignAndFocusPowder.h
index 2449316d53ba9829efd8920a3fefd3072f2181c6..48cba89c960bfabb30e5691ffc786d1a2da00d2b 100644
--- a/Code/Mantid/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/AlignAndFocusPowder.h
+++ b/Code/Mantid/Framework/WorkflowAlgorithms/inc/MantidWorkflowAlgorithms/AlignAndFocusPowder.h
@@ -75,6 +75,7 @@ namespace Mantid
       void init();
       void exec();
       void loadCalFile(const std::string &calFileName);
+      void rebin();
       API::MatrixWorkspace_sptr m_inputW;
       API::MatrixWorkspace_sptr m_outputW;
       DataObjects::EventWorkspace_sptr m_inputEW;
diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp b/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp
index 7c864dfacc3f667d269c39213e9164c84f13a2dc..3020f74a12b748fc13c6e2940bae27bb4fe7cde4 100644
--- a/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp
+++ b/Code/Mantid/Framework/WorkflowAlgorithms/src/AlignAndFocusPowder.cpp
@@ -279,30 +279,7 @@ void AlignAndFocusPowder::exec()
   m_outputW = maskAlg->getProperty("Workspace");
 
   if(!dspace)
-  {
-    if (m_resampleX != 0)
-    {
-      g_log.information() << "running ResampleX(NumberBins=" << abs(m_resampleX)
-                          << ", LogBinning=" << (m_resampleX < 0) << ")\n";
-      API::IAlgorithm_sptr alg = createChildAlgorithm("ResampleX");
-      alg->setProperty("InputWorkspace", m_outputW);
-      alg->setProperty("OutputWorkspace", m_outputW);
-      alg->setProperty("NumberBins", abs(m_resampleX));
-      alg->setProperty("LogBinning", (m_resampleX < 0));
-      alg->executeAsChildAlg();
-      m_outputW = alg->getProperty("OutputWorkspace");
-    }
-    else
-    {
-      g_log.information() << "running Rebin\n";
-	  API::IAlgorithm_sptr rebin1Alg = createChildAlgorithm("Rebin");
-	  rebin1Alg->setProperty("InputWorkspace", m_outputW);
-	  rebin1Alg->setProperty("OutputWorkspace", m_outputW);
-      rebin1Alg->setProperty("Params",m_params);
-	  rebin1Alg->executeAsChildAlg();
-	  m_outputW = rebin1Alg->getProperty("OutputWorkspace");
-    }
-  }
+    this->rebin();
 
   g_log.information() << "running AlignDetectors\n";
   API::IAlgorithm_sptr alignAlg = createChildAlgorithm("AlignDetectors");
@@ -375,30 +352,7 @@ void AlignAndFocusPowder::exec()
   }
 
   if(dspace)
-  {
-    if (m_resampleX != 0)
-    {
-      g_log.information() << "running ResampleX(NumberBins=" << abs(m_resampleX)
-                          << ", LogBinning=" << (m_resampleX < 0) << ")\n";
-      API::IAlgorithm_sptr alg = createChildAlgorithm("ResampleX");
-      alg->setProperty("InputWorkspace", m_outputW);
-      alg->setProperty("OutputWorkspace", m_outputW);
-      alg->setProperty("NumberBins", abs(m_resampleX));
-      alg->setProperty("LogBinning", (m_resampleX < 0));
-      alg->executeAsChildAlg();
-      m_outputW = alg->getProperty("OutputWorkspace");
-    }
-    else
-    {
-      g_log.information() << "running Rebin\n";
-	  API::IAlgorithm_sptr rebin2Alg = createChildAlgorithm("Rebin");
-	  rebin2Alg->setProperty("InputWorkspace", m_outputW);
-	  rebin2Alg->setProperty("OutputWorkspace", m_outputW);
-      rebin2Alg->setProperty("Params",m_params);
-	  rebin2Alg->executeAsChildAlg();
-	  m_outputW = rebin2Alg->getProperty("OutputWorkspace");
-    }
-  }
+    this->rebin();
 
   doSortEvents(m_outputW);
 
@@ -441,6 +395,15 @@ void AlignAndFocusPowder::exec()
     m_params.erase(m_params.begin());
     m_params.pop_back();
   }
+  if (!dspace)
+    this->rebin();
+
+  // return the output workspace
+  setProperty("OutputWorkspace",m_outputW);
+}
+
+void AlignAndFocusPowder::rebin()
+{
   if (m_resampleX != 0)
   {
     g_log.information() << "running ResampleX(NumberBins=" << abs(m_resampleX)
@@ -463,9 +426,6 @@ void AlignAndFocusPowder::exec()
     rebin3Alg->executeAsChildAlg();
     m_outputW = rebin3Alg->getProperty("OutputWorkspace");
   }
-
-  // return the output workspace
-  setProperty("OutputWorkspace",m_outputW);
 }
 
 /**