diff --git a/src/Makefile.am b/src/Makefile.am
index 2c049dc3a2215a0ebd5a96f2a293972ae3e49970..30d38c3092b2a240bb644a4dff8d48dc5458f931 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -45,7 +45,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
     physical_constants.h physical_constants_cgs.h potential.h version.h \
     hydro_properties.h riemann.h threadpool.h cooling.h cooling_struct.h sourceterms.h \
     sourceterms_struct.h statistics.h memswap.h cache.h runner_doiact_vec.h profiler.h \
-    dump.h logger.h active.h timeline.h sort.h xmf.h gravity_properties.h gravity_derivatives.h
+    dump.h logger.h active.h timeline.h sort_part.h xmf.h gravity_properties.h gravity_derivatives.h
 
 # Common source files
 AM_SOURCES = space.c runner.c queue.c task.c cell.c engine.c \
diff --git a/src/cache.h b/src/cache.h
index 6af5ce2871d5118b8a11f0c8d62fd88e0417e5e3..19bbeca0473c8a9e66306095d12b0dc6379c60a9 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -26,7 +26,7 @@
 #include "cell.h"
 #include "error.h"
 #include "part.h"
-#include "sort.h"
+#include "sort_part.h"
 #include "vector.h"
 
 #define NUM_VEC_PROC 2
diff --git a/src/runner.c b/src/runner.c
index 4296a781444aee7e15a2ae607d5c0e9998131da6..d2120e3992f49c2721b1f0c583460229c5937dcc 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -55,6 +55,7 @@
 #include "minmax.h"
 #include "runner_doiact_vec.h"
 #include "scheduler.h"
+#include "sort_part.h"
 #include "sourceterms.h"
 #include "space.h"
 #include "stars.h"
diff --git a/src/runner.h b/src/runner.h
index 5f175cec5a843ea25429a8433fe8c7061faeffce..9388679b2abd6593010e82e7768643673dbc266a 100644
--- a/src/runner.h
+++ b/src/runner.h
@@ -24,7 +24,6 @@
 #define SWIFT_RUNNER_H
 
 #include "cache.h"
-#include "sort.h"
 
 extern const double runner_shift[13][3];
 extern const char runner_flip[27];
diff --git a/src/sort.h b/src/sort.h
deleted file mode 100644
index 62f4eab53d85265f67e3ab9e5d84d862c215b4d6..0000000000000000000000000000000000000000
--- a/src/sort.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * This file is part of SWIFT.
- * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
- *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
- *               2015 Peter W. Draper (p.w.draper@durham.ac.uk)
- *               2016 John A. Regan (john.a.regan@durham.ac.uk)
- *                    Tom Theuns (tom.theuns@durham.ac.uk)
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- ******************************************************************************/
-#ifndef SWIFT_SORT_H
-#define SWIFT_SORT_H
-
-/**
- * @brief  Entry in a list of sorted indices.
- */
-struct entry {
-
-  /*! Distance on the axis */
-  float d;
-
-  /*! Particle index */
-  int i;
-};
-
-#endif
diff --git a/src/sort_part.h b/src/sort_part.h
new file mode 100644
index 0000000000000000000000000000000000000000..b204aaa393324f0ef80b1ae4451f32d0d947e65f
--- /dev/null
+++ b/src/sort_part.h
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * This file is part of SWIFT.
+ * Copyright (c) 2017 James S. Wills (james.s.willis@durham.ac.uk)
+ *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ ******************************************************************************/
+#ifndef SWIFT_SORT_PART_H
+#define SWIFT_SORT_PART_H
+
+/**
+ * @brief Entry in a list of sorted indices.
+ */
+struct entry {
+
+  /*! Distance on the axis */
+  float d;
+
+  /*! Particle index */
+  int i;
+};
+
+/**
+ * @brief Determines whether a pair of cells are corner to corner.
+ *
+ * @param sid sort ID
+ *
+ * @return 1 if corner to corner, 0 otherwise.
+ */
+__attribute__((always_inline)) INLINE static int sort_is_corner(int sid) {
+  return (sid == 0 || sid == 2 || sid == 6 || sid == 8);
+}
+
+/**
+ * @brief Determines whether a pair of cells are edge to edge.
+ *
+ * @param sid sort ID
+ *
+ * @return 1 if edge to edge, 0 otherwise.
+ */
+__attribute__((always_inline)) INLINE static int sort_is_edge(int sid) {
+  return (sid == 1 || sid == 3 || sid == 5 || sid == 7 || sid == 9 || sid == 11);
+}
+
+/**
+ * @brief Determines whether a pair of cells are face to face.
+ *
+ * @param sid sort ID
+ *
+ * @return 1 if face to face, 0 otherwise.
+ */
+__attribute__((always_inline)) INLINE static int sort_is_face(int sid) {
+  return (sid == 4 || sid == 10 || sid == 12);
+}
+
+
+#endif /* SWIFT_SORT_PART_H */
diff --git a/src/space.c b/src/space.c
index 75305f47e1bf0828d293e42d76bd87e1152bdbba..64a9ab15c960e7664afdf6be4293bbad3176fc76 100644
--- a/src/space.c
+++ b/src/space.c
@@ -171,17 +171,6 @@ int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
   return sid;
 }
 
-/**
- * @brief Determines whether a pair of cells are corner to corner.
- *
- * @param sort ID
- *
- * @return True if corner to corner
- */
-int space_iscorner(int sid) {
-  return (sid == 0 || sid == 2 || sid == 6 || sid == 8);
-}
-
 /**
  * @brief Recursively dismantle a cell tree.
  *
@@ -2111,10 +2100,10 @@ void space_split_recursive(struct space *s, struct cell *c,
       for (int k = 0; k < 8; ++k) {
         if (c->progeny[k] != NULL) {
           const struct gravity_tensors *m = c->progeny[k]->multipole;
-          CoM[0] += m->CoM[0] * m->m_pole.mass;
-          CoM[1] += m->CoM[1] * m->m_pole.mass;
-          CoM[2] += m->CoM[2] * m->m_pole.mass;
-          mass += m->m_pole.mass;
+          CoM[0] += m->CoM[0] * m->m_pole.M_000;
+          CoM[1] += m->CoM[1] * m->m_pole.M_000;
+          CoM[2] += m->CoM[2] * m->m_pole.M_000;
+          mass += m->m_pole.M_000;
         }
       }
       c->multipole->CoM[0] = CoM[0] / mass;
@@ -2703,6 +2692,8 @@ void space_init(struct space *s, const struct swift_params *params,
     bzero(s->xparts, Npart * sizeof(struct xpart));
   }
 
+  hydro_space_init(&s->hs, s);
+
   /* Set the particles in a state where they are ready for a run */
   space_init_parts(s);
   space_init_xparts(s);
diff --git a/src/space.h b/src/space.h
index e110faa68f1dce4cfc4c7ae9dad47fd5d45352d7..73bd50da928c55890a91415f6e07c5100a7b71e7 100644
--- a/src/space.h
+++ b/src/space.h
@@ -31,6 +31,7 @@
 
 /* Includes. */
 #include "cell.h"
+#include "hydro_space.h"
 #include "lock.h"
 #include "parser.h"
 #include "part.h"
@@ -69,12 +70,12 @@ struct space {
   /*! Is the space periodic? */
   int periodic;
 
+  /*! Extra space information needed for some hydro schemes. */
+  struct hydro_space hs;
+
   /*! Are we doing gravity? */
   int gravity;
 
-  /*! Total mass in the system */
-  double total_mass;
-
   /*! Width of the top-level cells. */
   double width[3];
 
@@ -169,7 +170,6 @@ void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
 void space_sparts_sort(struct space *s, int *ind, size_t N, int min, int max,
                        int verbose);
 void space_getcells(struct space *s, int nr_cells, struct cell **cells);
-int space_iscorner(int sid);
 int space_getsid(struct space *s, struct cell **ci, struct cell **cj,
                  double *shift);
 void space_init(struct space *s, const struct swift_params *params,