Index: src/Actions/FragmentationAction/FragmentationAutomationAction.cpp
===================================================================
--- src/Actions/FragmentationAction/FragmentationAutomationAction.cpp	(revision 1e7dd43451cc813dbdf63921c91127e6add87249)
+++ src/Actions/FragmentationAction/FragmentationAutomationAction.cpp	(revision c5324f5fef866d52eb12447aaca117dcf2dba87d)
@@ -276,45 +276,56 @@
 }
 
-Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
-  boost::asio::io_service io_service;
-  FragmentController controller(io_service);
-
-  // TODO: Have io_service run in second thread and merge with current again eventually
-
-  // Phase One: obtain ids
-  std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
-  controller.requestIds(params.host.get(), params.port.get(), jobfiles.size());
-  {
-    io_service.reset();
-    Info info("io_service: Phase One");
-    io_service.run();
-  }
-  // Phase Two: create and add jobs
-  {
-    std::vector<FragmentJob::ptr> jobs;
-    for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles .begin();
-        iter != jobfiles .end(); ++iter) {
-      const std::string &filename = (*iter).string();
-      if (boost::filesystem::exists(filename)) {
-        const JobId_t next_id = controller.getAvailableId();
-        LOG(1, "INFO: Creating MPQCCommandJob with filename'"
-            +filename+"', and id "+toString(next_id)+".");
-        parsejob(jobs, params.executable.get().string(), filename, next_id);
-      } else {
-        ELOG(1, "Fragment job "+filename+" does not exist.");
-        return Action::failure;
-      }
+
+void RunService(
+    boost::asio::io_service &io_service,
+    std::string message)
+{
+  message = std::string("io_service: ") + message;
+  io_service.reset();
+  Info info(message.c_str());
+  io_service.run();
+}
+
+void requestIds(
+    FragmentController &controller,
+    const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
+    const size_t numberjobs)
+{
+  controller.requestIds(params.host.get(), params.port.get(), numberjobs);
+}
+
+bool createJobsFromFiles(
+    FragmentController &controller,
+    const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
+    const std::vector< boost::filesystem::path > &jobfiles)
+{
+  std::vector<FragmentJob::ptr> jobs;
+  for (std::vector< boost::filesystem::path >::const_iterator iter = jobfiles.begin();
+      iter != jobfiles .end(); ++iter) {
+    const std::string &filename = (*iter).string();
+    if (boost::filesystem::exists(filename)) {
+      const JobId_t next_id = controller.getAvailableId();
+      LOG(1, "INFO: Creating MPQCCommandJob with filename'"
+          +filename+"', and id "+toString(next_id)+".");
+      parsejob(jobs, params.executable.get().string(), filename, next_id);
+    } else {
+      ELOG(1, "Fragment job "+filename+" does not exist.");
+      return false;
     }
-    controller.addJobs(jobs);
-    controller.sendJobs(params.host.get(), params.port.get());
-  }
-  {
-    io_service.reset();
-    Info info("io_service: Phase Two");
-    io_service.run();
-  }
-  // Phase Three: calculate result
+  }
+  controller.addJobs(jobs);
+  controller.sendJobs(params.host.get(), params.port.get());
+  return true;
+}
+
+void WaitforResults(
+    boost::asio::io_service &io_service,
+    FragmentController &controller,
+    const FragmentationFragmentationAutomationAction::FragmentationFragmentationAutomationParameters &params,
+    const size_t NoExpectedResults
+    )
+{
   size_t NoCalculatedResults = 0;
-  while (NoCalculatedResults != jobfiles.size()) {
+  while (NoCalculatedResults != NoExpectedResults) {
     // wait a bit
     boost::asio::deadline_timer timer(io_service);
@@ -323,20 +334,36 @@
     // then request status
     controller.checkResults(params.host.get(), params.port.get());
-    {
-      io_service.reset();
-      Info info("io_service: Phase Three");
-      io_service.run();
-    }
+    RunService(io_service, "Checking on results");
+
     const std::pair<size_t, size_t> JobStatus = controller.getJobStatus();
     LOG(1, "INFO: #" << JobStatus.first << " are waiting in the queue and #" << JobStatus.second << " jobs are calculated so far.");
     NoCalculatedResults = JobStatus.second;
   }
+}
+
+
+Action::state_ptr FragmentationFragmentationAutomationAction::performCall() {
+  boost::asio::io_service io_service;
+  FragmentController controller(io_service);
+
+  // TODO: Have io_service run in second thread and merge with current again eventually
+
+  // Phase One: obtain ids
+  std::vector< boost::filesystem::path > jobfiles = params.jobfiles.get();
+  requestIds(controller, params, jobfiles.size());
+  RunService(io_service, "Requesting ids");
+
+  // Phase Two: create and add jobs
+  if (!createJobsFromFiles(controller, params, jobfiles))
+    return Action::failure;
+  RunService(io_service, "Adding jobs");
+
+  // Phase Three: calculate result
+  WaitforResults(io_service, controller, params, jobfiles.size());
+
   // Phase Three: get result
   controller.receiveResults(params.host.get(), params.port.get());
-  {
-    io_service.reset();
-    Info info("io_service: Phase Four");
-    io_service.run();
-  }
+  RunService(io_service, "Phase Four");
+
   // Final phase: print result
   {
