diff --git a/src/black_holes_io.h b/src/black_holes_io.h
index bc3b1be3be44588794ababfc9500be7812c14f5e..babe30656083d1e7e7b493850c421c562a2ce1ee 100644
--- a/src/black_holes_io.h
+++ b/src/black_holes_io.h
@@ -21,6 +21,9 @@
 
 #include "../config.h"
 
+/* Local includes */
+#include "engine.h"
+
 /* Load the correct star type */
 #if defined(BLACK_HOLES_NONE)
 #include "./black_holes/Default/black_holes_io.h"
diff --git a/src/distributed_io.c b/src/distributed_io.c
index 93d39815eb5608ab1aeb60167172753595cc39d2..8a5a21f4fc555d4d27b33b34853669f2010b5e22 100644
--- a/src/distributed_io.c
+++ b/src/distributed_io.c
@@ -54,6 +54,7 @@
 #include "part_type.h"
 #include "star_formation_io.h"
 #include "stars_io.h"
+#include "tools.h"
 #include "tracers_io.h"
 #include "units.h"
 #include "velociraptor_io.h"
@@ -220,16 +221,19 @@ void write_distributed_array(const struct engine* e, hid_t grp,
  * @brief Writes a snapshot distributed into multiple files.
  *
  * @param e The engine containing all the system.
- * @param baseName The common part of the snapshot file name.
  * @param internal_units The #unit_system used internally
  * @param snapshot_units The #unit_system used in the snapshots
+ * @param mpi_rank The rank number of the calling MPI rank.
+ * @param mpi_size the number of MPI ranks.
+ * @param comm The communicator used by the MPI ranks.
+ * @param info The MPI information object.
  *
  * Creates a series of HDF5 output files (1 per MPI node) as a snapshot.
  * Writes the particles contained in the engine.
  * If such files already exist, it is erased and replaced by the new one.
  * The companion XMF file is also updated accordingly.
  */
-void write_output_distributed(struct engine* e, const char* baseName,
+void write_output_distributed(struct engine* e,
                               const struct unit_system* internal_units,
                               const struct unit_system* snapshot_units,
                               const int mpi_rank, const int mpi_size,
@@ -317,8 +321,8 @@ void write_output_distributed(struct engine* e, const char* baseName,
   }
 
   /* Create the directory */
-  if (mpi_rank == 0) mkdir(dirName, 0777);
-  MPI_Barrier(MPI_COMM_WORLD);
+  if (mpi_rank == 0) safe_checkdir(dirName, /*create=*/1);
+  MPI_Barrier(comm);
 
   /* Compute offset in the file and total number of particles */
   const long long N[swift_type_count] = {Ngas_written,   Ndm_written,
diff --git a/src/distributed_io.h b/src/distributed_io.h
index 3331c5a36080569fd801de29ee49de47ed66a580..41b2740ecede0b919a738c55350e2c62c731a604 100644
--- a/src/distributed_io.h
+++ b/src/distributed_io.h
@@ -29,13 +29,10 @@
 #include <mpi.h>
 #endif
 
-/* Includes. */
-#include "engine.h"
-#include "io_properties.h"
-#include "part.h"
-#include "units.h"
+struct engine;
+struct unit_system;
 
-void write_output_distributed(struct engine* e, const char* baseName,
+void write_output_distributed(struct engine* e,
                               const struct unit_system* internal_units,
                               const struct unit_system* snapshot_units,
                               int mpi_rank, int mpi_size, MPI_Comm comm,
diff --git a/src/engine.c b/src/engine.c
index c3f163c52bbbef8143dddcb8f622d75fe68893b8..487e5cdcf3b70858a7b68e716a669fd15d909015 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -3616,9 +3616,8 @@ void engine_dump_snapshot(struct engine *e) {
 
   if (e->snapshot_distributed) {
 
-    write_output_distributed(e, snapshotBase, e->internal_units,
-                             e->snapshot_units, e->nodeID, e->nr_nodes,
-                             MPI_COMM_WORLD, MPI_INFO_NULL);
+    write_output_distributed(e, e->internal_units, e->snapshot_units, e->nodeID,
+                             e->nr_nodes, MPI_COMM_WORLD, MPI_INFO_NULL);
   } else {
 
 #if defined(HAVE_PARALLEL_HDF5)
diff --git a/src/parallel_io.h b/src/parallel_io.h
index 6f1b397ef337c05da99a8017cc562212067e32a5..08588ee3d3292e5a765a9941c10f72e6aab82a2a 100644
--- a/src/parallel_io.h
+++ b/src/parallel_io.h
@@ -28,10 +28,10 @@
 #include <mpi.h>
 
 /* Includes. */
-#include "engine.h"
-#include "io_properties.h"
 #include "part.h"
-#include "units.h"
+
+struct engine;
+struct unit_system;
 
 void read_ic_parallel(char* fileName, const struct unit_system* internal_units,
                       double dim[3], struct part** parts, struct gpart** gparts,
diff --git a/src/serial_io.h b/src/serial_io.h
index 02b3a22fa64e0ecef2076de9da77de3e303c325c..1146e5f5fb9767f94c5e76195cabbc893db25e14 100644
--- a/src/serial_io.h
+++ b/src/serial_io.h
@@ -30,10 +30,10 @@
 #endif
 
 /* Includes. */
-#include "engine.h"
-#include "io_properties.h"
 #include "part.h"
-#include "units.h"
+
+struct engine;
+struct unit_system;
 
 void read_ic_serial(char* fileName, const struct unit_system* internal_units,
                     double dim[3], struct part** parts, struct gpart** gparts,
diff --git a/src/single_io.h b/src/single_io.h
index a28b06979fe86bc37ff262e7462cd8eb773bcef7..c341fda920e25d9c109e85e6b0967355f09fa6be 100644
--- a/src/single_io.h
+++ b/src/single_io.h
@@ -24,11 +24,11 @@
 
 #if defined(HAVE_HDF5) && !defined(WITH_MPI)
 
-/* Includes. */
-#include "engine.h"
-#include "io_properties.h"
+/* Local includes */
 #include "part.h"
-#include "units.h"
+
+struct engine;
+struct unit_system;
 
 void read_ic_single(const char* fileName,
                     const struct unit_system* internal_units, double dim[3],