diff --git a/examples/main.c b/examples/main.c
index 0af9cc2160c79dc90063620c2346ede84e67ce03..2a3e9e95c6a0701b37a22b4c371acc876230253c 100644
--- a/examples/main.c
+++ b/examples/main.c
@@ -890,6 +890,9 @@ int main(int argc, char *argv[]) {
     if (with_structure_finding)
       engine_policies |= engine_policy_structure_finding;
 
+    /* Initialise the FOF parameters. */
+    fof_init(&s, N_total[0], N_total[1]);
+      
     /* Initialize the engine with the space and policies. */
     if (myrank == 0) clocks_gettime(&tic);
     engine_init(&e, &s, params, N_total[0], N_total[1], N_total[2],
diff --git a/src/engine.c b/src/engine.c
index bd1b25af5973a4549a60eb06c1415e82e24fe672..606361259712abc18302d36054993073087b6998 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -4606,19 +4606,8 @@ void engine_init_particles(struct engine *e, int flag_entropy_ICs,
 
   message("Performing Friends Of Friends search.");
 
-  /* Calculate the particle linking length based upon the mean inter-particle
-   * spacing. */
-  const int total_nr_dmparts = e->total_nr_gparts - e->total_nr_parts;
-  const double l_x = 0.2 * (s->dim[0] / cbrt(total_nr_dmparts));
-  s->l_x2 = l_x * l_x;
 
   ticks tic = getticks();
-  //fof_search_serial(s);
-  message("Serial FOF search took: %.3f %s.",
-          clocks_from_ticks(getticks() - tic), clocks_getunit());
-
-  tic = getticks();
-  //fof_search_tree_serial(s);
   fof_search_tree(s);
   message("Serial tree FOF search took: %.3f %s.",
           clocks_from_ticks(getticks() - tic), clocks_getunit());
diff --git a/src/fof.c b/src/fof.c
index 0d029752eeef65977e0ed3f1965c1e4cbcc02861..9324fad2b54ee279b894d69c965b257c4fbca54d 100644
--- a/src/fof.c
+++ b/src/fof.c
@@ -27,6 +27,16 @@
 #include "threadpool.h"
 #include "engine.h"
 
+/* Initialises parameters for the FOF search. */
+void fof_init(struct space *s, long long Ngas, long long Ngparts) {
+
+  /* Calculate the particle linking length based upon the mean inter-particle
+   * spacing of the DM particles. */
+  const int total_nr_dmparts = Ngparts - Ngas;
+  const double l_x = 0.2 * (s->dim[0] / cbrt(total_nr_dmparts));
+  s->l_x2 = l_x * l_x;
+}
+
 /* Finds the root ID of the group a particle exists in. */
 __attribute__((always_inline)) INLINE static int fof_find(const int i,
                                                           int *group_id) {
diff --git a/src/fof.h b/src/fof.h
index 658ef1c0b00066fe996db0f5af3619cd23801ac2..5e8809c298455565b2ba2653c52806d2c34b863b 100644
--- a/src/fof.h
+++ b/src/fof.h
@@ -28,6 +28,7 @@
 #include "space.h"
 
 /* Function prototypes. */
+void fof_init(struct space *s, long long Ngas, long long Ngparts);
 void fof_search_serial(struct space *s);
 void fof_search_cell(struct space *s, struct cell *c);
 void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj);