diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000000000000000000000000000000000000..40c61f96f1dbd77e1caebebedd95ffbe8d61ac05
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,68 @@
+# This file is part of PySWIFTsim.
+# Copyright (c) 2019 Loic Hausammann (loic.hausammann@epfl.ch).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU 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 General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Add the non-standard paths to the included library headers
+AM_CFLAGS = -I$(top_srcdir)/src $(HDF5_CPPFLAGS) $(GSL_INCS) $(FFTW_INCS) $(NUMA_INCS) $(GRACKLE_INCS) $(PYTHON_INCS)
+
+# Assign a "safe" version number
+AM_LDFLAGS = $(HDF5_LDFLAGS) $(FFTW_LIBS) -version-info 0:0:0
+
+# The git command, if available.
+GIT_CMD = @GIT_CMD@
+
+# Additional dependencies for shared libraries.
+EXTRA_LIBS = $(HDF5_LIBS) $(FFTW_LIBS) $(NUMA_LIBS) $(PROFILER_LIBS) $(TCMALLOC_LIBS) \
+	$(JEMALLOC_LIBS) $(TBBMALLOC_LIBS) $(GRACKLE_LIBS) $(GSL_LIBS) $(PYTHON_LIBS) \
+	$(top_srcdir)/src/.libs
+
+# MPI libraries.
+MPI_LIBS = $(PARMETIS_LIBS) $(METIS_LIBS) $(MPI_THREAD_LIBS)
+MPI_FLAGS = -DWITH_MPI $(PARMETIS_INCS) $(METIS_INCS)
+
+# Build the libswiftsim library
+lib_LTLIBRARIES = libpyswiftsim.la
+# Build a MPI-enabled version too?
+if HAVEMPI
+lib_LTLIBRARIES += libpyswiftsim_mpi.la
+endif
+
+# List required headers
+include_HEADERS = chemistry_wrapper.h cooling_wrapper.h \
+	cosmology_wrapper.h parser_wrapper.h part_wrapper.h \
+	pyswiftsim_tools.h units_wrapper.h
+
+
+# Common source files
+AM_SOURCES = chemistry_wrapper.c cooling_wrapper.c cosmology_wrapper.c \
+	parser_wrapper.c part_wrapper.c pyswiftsim_tools.c \
+	units_wrapper.c wrapper.c
+
+# Include files for distribution, not installation.
+nobase_noinst_HEADERS = 
+
+# Sources and flags for regular library
+libpyswiftsim_la_SOURCES = $(AM_SOURCES)
+libpyswiftsim_la_CFLAGS = $(AM_CFLAGS)
+libpyswiftsim_la_LDFLAGS = $(AM_LDFLAGS) $(EXTRA_LIBS) -lswiftsim
+libpyswiftsim_la_LIBADD = $(GRACKLE_LIBS) $(VELOCIRAPTOR_LIBS)
+
+# Sources and flags for MPI library
+libpyswiftsim_mpi_la_SOURCES = $(AM_SOURCES)
+libpyswiftsim_mpi_la_CFLAGS = $(AM_CFLAGS) $(MPI_FLAGS)
+libpyswiftsim_mpi_la_LDFLAGS = $(AM_LDFLAGS) $(MPI_LIBS) $(EXTRA_LIBS) -lswiftsim_mpi
+libpyswiftsim_mpi_la_SHORTNAME = mpi
+libpyswiftsim_mpi_la_LIBADD = $(GRACKLE_LIBS) $(VELOCIRAPTOR_LIBS)
+
diff --git a/src/config_wrapper.h b/src/config_wrapper.h
deleted file mode 100644
index 24b866f604bff1d1f502e4462fe00a0616b5323a..0000000000000000000000000000000000000000
--- a/src/config_wrapper.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * This file is part of PYSWIFTSIM.
- * Copyright (c) 2018 loic hausammann (loic.hausammann@epfl.ch)
- *
- * 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  __PYSWIFTSIM_CONFIG_H__
-#define  __PYSWIFTSIM_CONFIG_H__
-
-#include "pyswiftsim_tools.h"
-
-/**
- * @brief give the cooling type name
- *
- * @return Cooling name (PyUnicode)
- */
-PyObject* config_get_cooling() {
-  char *cooling_name = "Not implemented";
-  /* lambda */
-#ifdef COOLING_CONST_LAMBDA
-  cooling_name = "const_lambda";
-
-  /* grackle */
-#elif defined(COOLING_GRACKLE)
-#if COOLING_GRACKLE_MODE == 0
-  cooling_name = "grackle";
-#elif COOLING_GRACKLE_MODE == 1
-  cooling_name = "grackle1";
-#elif COOLING_GRACKLE_MODE == 2
-  cooling_name = "grackle2";  
-#elif COOLING_GRACKLE_MODE == 3
-  cooling_name = "grackle3";
-#else
-  error("Grackle mode unknown");
-#endif // COOLING_GRACKLE_MODE
-#endif // COOLING_GRACKLE
-  
-  return PyUnicode_FromString(cooling_name);
-};
-
-
-#endif //  __PYSWIFTSIM_CONFIG_H__
diff --git a/src/cooling_wrapper.c b/src/cooling_wrapper.c
index 49fc0afc2824120d4beae4609d3e263310c2618d..242dc7f76930d1bcafc734a0e4aff3830d73380b 100644
--- a/src/cooling_wrapper.c
+++ b/src/cooling_wrapper.c
@@ -114,7 +114,7 @@ void pycooling_set_fractions(struct xpart *xp, PyArrayObject* frac, const int id
  * @param args arguments
  * @return cooling rate
  */
-PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
+PyObject* pycooling_rate(PyObject* self, PyObject* args) {
   import_array();
   
   PyObject *pycooling;
@@ -190,13 +190,12 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
   struct xpart xp;
 
   /* return object */
-  PyArrayObject *rate = PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT);
+  PyArrayObject *rate = (PyArrayObject *)PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT);
 
   /* Release GIL */
   Py_BEGIN_ALLOW_THREADS;
   
   /* loop over all particles */
-#pragma omp for
   for(size_t i = 0; i < N; i++)
     {
       /* set particle data */
@@ -214,7 +213,10 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
       /* compute cooling rate */
 #ifdef COOLING_GRACKLE
       float *tmp = PyArray_GETPTR1(rate, i);
-      *tmp = cooling_rate(pconst, us, cosmo, cooling, &p, &xp, dt);
+      *tmp = cooling_new_energy(pconst, us, cosmo, cooling, &p, &xp, dt);
+      *tmp = *tmp - hydro_get_physical_internal_energy(&p, &xp, cosmo);
+      *tmp /= dt;
+      message("%g", *tmp);
 #else
       message("Not implemented");
       //*tmp = cooling_rate(pconst, us, cosmo, cooling, &p, &xp);
@@ -224,7 +226,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
   /* Acquire GIL */
   Py_END_ALLOW_THREADS;
 
-  return rate;
+  return (PyObject *) rate;
   
 }
 
@@ -241,7 +243,7 @@ PyArrayObject* pycooling_rate(PyObject* self, PyObject* args) {
  * @param args arguments
  * @return New energy
  */
-PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) {
+PyObject* pycooling_do_cooling(PyObject* self, PyObject* args) {
   import_array();
   
   PyObject *pycooling;
@@ -322,13 +324,12 @@ PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) {
 #endif
 
   /* return object */
-  PyArrayObject *new_energy = PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT);
+  PyArrayObject *new_energy = (PyArrayObject *)PyArray_SimpleNew(PyArray_NDIM(energy), PyArray_DIMS(energy), NPY_FLOAT);
 
   /* Release GIL */
   Py_BEGIN_ALLOW_THREADS;
   
   /* loop over all particles */
-#pragma omp for
   for(size_t i = 0; i < N; i++)
     {
       /* set particle data */
@@ -358,6 +359,6 @@ PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args) {
   /* Acquire GIL */
   Py_END_ALLOW_THREADS;
 
-  return new_energy;
+  return (PyObject *) new_energy;
   
 }
diff --git a/src/cooling_wrapper.h b/src/cooling_wrapper.h
index f39dc449e4a47e0c16a45f9395962b7a3e12ae4e..e80cb1c38f7d97d2b00ac7161d8c98f9cbcaf578 100644
--- a/src/cooling_wrapper.h
+++ b/src/cooling_wrapper.h
@@ -23,9 +23,9 @@
 
 PyObject* pycooling_init(PyObject* self, PyObject* args);
 
-PyArrayObject* pycooling_rate(PyObject* self, PyObject* args);
+PyObject* pycooling_rate(PyObject* self, PyObject* args);
 
-PyArrayObject* pycooling_do_cooling(PyObject* self, PyObject* args);
+PyObject* pycooling_do_cooling(PyObject* self, PyObject* args);
 
 #endif // __PYSWIFTSIM_COOLING_H__
 
diff --git a/src/pyswiftsim_tools.c b/src/pyswiftsim_tools.c
index cc2d5fa3346963ddb9ba327cf6629d7c541a7cc9..5b872ec5a283030da0420dbb0bf05a38b43e774d 100644
--- a/src/pyswiftsim_tools.c
+++ b/src/pyswiftsim_tools.c
@@ -137,7 +137,7 @@ char* pytools_get_type_name(PyObject *obj)
     pyerror("Requires a non null object");
   
   /* get object type */
-  PyObject *type = obj->ob_type;
+  PyObject *type = (PyObject *)obj->ob_type;
   if (type == NULL)
       pyerror("Unable to get type");
 
diff --git a/src/pyswiftsim_tools.h b/src/pyswiftsim_tools.h
index 312ba2cc097f1b5fc68ed4309da14a42bd5d5400..ca2b0d03129c88da287f71e7ccb78342fb35c094 100644
--- a/src/pyswiftsim_tools.h
+++ b/src/pyswiftsim_tools.h
@@ -25,7 +25,8 @@
 #include <numpy/arrayobject.h>
 
 #undef assert
-#include <swift.h>
+#include "../config.h"
+#include "swift.h"
 
 #define DIM 3
 #define STRING_SIZE 200
diff --git a/src/wrapper.c b/src/wrapper.c
index 5a119f2cea70a741a0b9a2ea14345f2f4b409050..2bc1f5f830bce9fd56773c3017f069394b0bae92 100644
--- a/src/wrapper.c
+++ b/src/wrapper.c
@@ -23,7 +23,7 @@
 #include "cosmology_wrapper.h"
 #include "chemistry_wrapper.h"
 #include "pyswiftsim_tools.h"
-#include "config_wrapper.h"
+#include "swift.h"
 
 #include <Python.h>
 #include <math.h>
@@ -91,9 +91,6 @@ static PyMethodDef wrapper_methods[] = {
    "\t Energy of the particle after dt\n"
   },
 
-  {"configGetCooling", config_get_cooling, METH_VARARGS,
-   "Get the cooling type."},
-  
   {NULL, NULL, 0, NULL}        /* Sentinel */
 };      
       
@@ -104,11 +101,15 @@ static struct PyModuleDef wrapper_cmodule = {
   "wrapper",
   "Wrapper around the SPH cosmological simulation code SWIFT",
   -1,
-  wrapper_methods
+  wrapper_methods,
+  NULL, /* m_slots */
+  NULL, /* m_traverse */
+  NULL, /* m_clear */
+  NULL, /* m_free */
 };
 
 
-PyMODINIT_FUNC PyInit_wrapper(void)
+PyMODINIT_FUNC PyInit_libpyswiftsim(void)
 {
   PyObject *m;