diff --git a/force_bdss/io/workflow_writer.py b/force_bdss/io/workflow_writer.py
index 5ba53f1..4b95989 100644
--- a/force_bdss/io/workflow_writer.py
+++ b/force_bdss/io/workflow_writer.py
@@ -19,17 +19,34 @@ class WorkflowWriter(HasStrictTraits):
         """
         data = {
             "version": "1",
-            "workflow": {}
         }
 
-        wf_data = data["workflow"]
-        wf_data["mco"] = {
-            "id": workflow.mco.bundle.id,
-            "model_data": workflow.mco.__getstate__()
+        data["workflow"] = self._workflow_data(workflow)
+        json.dump(data, f)
+
+    def _workflow_data(self, workflow):
+        workflow_data = {
+            "mco": self._mco_data(workflow.mco),
+            "kpi_calculators": [
+                self._bundle_model_data(kpic)
+                for kpic in workflow.kpi_calculators],
+            "data_sources": [
+                self._bundle_model_data(ds)
+                for ds in workflow.data_sources]
         }
 
+        return workflow_data
+
+    def _mco_data(self, mco):
+        """Extracts the data from the MCO object and returns its dictionary.
+        If the MCO is None, returns None"""
+        if mco is None:
+            return None
+
+        data = self._bundle_model_data(mco)
+
         parameters_data = []
-        for param in wf_data["mco"]["model_data"]["parameters"]:  # noqa
+        for param in data["model_data"]["parameters"]:
             parameters_data.append(
                 {
                     "id": param.factory.id,
@@ -37,24 +54,14 @@ class WorkflowWriter(HasStrictTraits):
                 }
             )
 
-        wf_data["mco"]["model_data"]["parameters"] = parameters_data  # noqa
-
-        kpic_data = []
-        for kpic in workflow.kpi_calculators:
-            kpic_data.append({
-                "id": kpic.bundle.id,
-                "model_data": kpic.__getstate__()}
-            )
-
-        wf_data["kpi_calculators"] = kpic_data
-
-        ds_data = []
-        for ds in workflow.data_sources:
-            ds_data.append({
-                "id": ds.bundle.id,
-                "model_data": ds.__getstate__()
-            })
+        data["model_data"]["parameters"] = parameters_data
+        return data
 
-        wf_data["data_sources"] = ds_data
-
-        json.dump(data, f)
+    def _bundle_model_data(self, bundle_model):
+        """
+        Extracts the data from a bundle model and returns its dictionary
+        """
+        return {
+            "id": bundle_model.bundle.id,
+            "model_data": bundle_model.__getstate__()
+        }

Workflow writer cannot write with empty MCO
Workflow writer cannot write with empty MCO

```
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/pyface/ui/qt4/action/action_item.py", line 163, in _qt4_on_triggered
    self.controller.perform(action, action_event)
  File "/usr/local/lib/python2.7/dist-packages/pyface/tasks/action/task_action_controller.py", line 31, in perform
    return action.perform(event)
  File "/usr/local/lib/python2.7/dist-packages/pyface/tasks/action/listening_action.py", line 58, in perform
    method()
  File "/home/martin/force-wfmanager/force_wfmanager/wfmanager_task.py", line 63, in save_workflow
    writer.write(self.workflow, output)
  File "/home/martin/force-bdss/force_bdss/io/workflow_writer.py", line 27, in write
    "id": workflow.mco.bundle.id,
AttributeError: 'NoneType' object has no attribute 'bundle'```
diff --git a/force_bdss/io/tests/test_workflow_writer.py b/force_bdss/io/tests/test_workflow_writer.py
index df70880..4ce0b2a 100644
--- a/force_bdss/io/tests/test_workflow_writer.py
+++ b/force_bdss/io/tests/test_workflow_writer.py
@@ -52,6 +52,7 @@ class TestWorkflowWriter(unittest.TestCase):
         fp = StringIO()
         wf = self._create_mock_workflow()
         wfwriter.write(wf, fp)
+        print(fp.getvalue())
         fp.seek(0)
         wfreader = WorkflowReader(self.mock_registry)
         wf_result = wfreader.read(fp)
@@ -73,3 +74,13 @@ class TestWorkflowWriter(unittest.TestCase):
             )
         ]
         return wf
+
+    def test_write_and_read_empty_workflow(self):
+        wf = Workflow()
+        wfwriter = WorkflowWriter()
+        fp = StringIO()
+        wfwriter.write(wf, fp)
+        fp.seek(0)
+        wfreader = WorkflowReader(self.mock_registry)
+        wf_result = wfreader.read(fp)
+        self.assertIsNone(wf_result.mco)

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.9
requirements/dev_requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
apptools==5.3.0
click==8.1.8
coverage==7.8.0
envisage==7.0.3
exceptiongroup==1.2.2
flake8==7.2.0
-e git+https://github.com/force-h2020/force-bdss.git@be9184f644572292170972fb0a9afb07ae47297b#egg=force_bdss
importlib_metadata==8.6.1
iniconfig==2.1.0
mccabe==0.7.0
mock==5.2.0
numpy==2.0.2
packaging==24.2
pbr==6.1.1
pluggy==1.5.0
pycodestyle==2.13.0
pyface==8.0.0
pyflakes==3.3.2
pytest==8.3.5
six==1.17.0
stevedore==5.4.1
testfixtures==8.3.0
tomli==2.2.1
traits==7.0.2
traitsui==8.0.0
zipp==3.21.0

name: force-bdss
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - pip=25.0=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - apptools==5.3.0
      - click==8.1.8
      - coverage==7.8.0
      - envisage==7.0.3
      - exceptiongroup==1.2.2
      - flake8==7.2.0
      - importlib-metadata==8.6.1
      - iniconfig==2.1.0
      - mccabe==0.7.0
      - mock==5.2.0
      - numpy==2.0.2
      - packaging==24.2
      - pbr==6.1.1
      - pluggy==1.5.0
      - pycodestyle==2.13.0
      - pyface==8.0.0
      - pyflakes==3.3.2
      - pytest==8.3.5
      - six==1.17.0
      - stevedore==5.4.1
      - testfixtures==8.3.0
      - tomli==2.2.1
      - traits==7.0.2
      - traitsui==8.0.0
      - zipp==3.21.0
prefix: /opt/conda/envs/force-bdss

force_bdss/io/tests/test_workflow_writer.py::TestWorkflowWriter::test_write_and_read_empty_workflow
force_bdss/io/tests/test_workflow_writer.py::TestWorkflowWriter::test_write force_bdss/io/tests/test_workflow_writer.py::TestWorkflowWriter::test_write_and_read
force_bdss/io/workflow_writer.py
force_bdss/io/workflow_writer.py