diff --git a/xbob/learn/activation/activation.cpp b/xbob/learn/activation/activation.cpp
index 51ca12398d2d8b271ce1b29445cdf98d077f9734..995761fe3d5c5de97f181ba6ed21de5a31480232 100644
--- a/xbob/learn/activation/activation.cpp
+++ b/xbob/learn/activation/activation.cpp
@@ -8,10 +8,10 @@
  */
 
 #define XBOB_LEARN_ACTIVATION_MODULE
-#include "cleanup.h"
 #include <xbob.learn.activation/api.h>
 #include <xbob.io/api.h>
 #include <xbob.blitz/cppapi.h>
+#include <xbob.blitz/cleanup.h>
 #include <bob/machine/Activation.h>
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
diff --git a/xbob/learn/activation/cleanup.h b/xbob/learn/activation/cleanup.h
deleted file mode 100644
index d6f0011fece2edffea89ac756732595a3f2caefd..0000000000000000000000000000000000000000
--- a/xbob/learn/activation/cleanup.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * @author Andre Anjos <andre.anjos@idiap.ch>
- * @date Wed 11 Dec 08:42:53 2013 
- *
- * @brief Some C++ tricks to make our life dealing with Python references a bit
- * easier
- */
-
-#include <Python.h>
-#include <memory>
-
-/**
- * Calls Py_DECREF(x) on the input object x. Usage pattern:
- *
- * PyObject* x = ... // builds x with a new python reference
- * auto protected_x = make_safe(x);
- * 
- * After this point, no need to worry about DECREF'ing x anymore. 
- * You can still use `x' inside your code, or protected_x.get().
- */
-template <typename T> std::shared_ptr<T> make_safe(T* o) {
-  return std::shared_ptr<T>(o, [&](T* p){Py_DECREF(p);});
-}
-
-/**
- * Calls Py_XDECREF(x) on the input object x. Usage pattern:
- *
- * PyObject* x = ... // builds x with a new python reference, x may be NULL
- * auto protected_x = make_xsafe(x);
- * 
- * After this point, no need to worry about XDECREF'ing x anymore.
- * You can still use `x' inside your code, or protected_x.get(). Note
- * `x' may be NULL with this method.
- */
-template <typename T> std::shared_ptr<T> make_xsafe(T* o) {
-  return std::shared_ptr<T>(o, [&](T* p){Py_XDECREF(p);});
-}
diff --git a/xbob/learn/activation/include/xbob.learn.activation/api.h b/xbob/learn/activation/include/xbob.learn.activation/api.h
index 34383078ed135819abae27ba3d73223eff282bd7..21a1b18cbed0103726f14f61513ac0ecc7780f1b 100644
--- a/xbob/learn/activation/include/xbob.learn.activation/api.h
+++ b/xbob/learn/activation/include/xbob.learn.activation/api.h
@@ -234,6 +234,8 @@ typedef struct {
 
 # if !defined(NO_IMPORT_ARRAY)
 
+#include <xbob.io/api.h>
+
   /**
    * Returns -1 on error, 0 on success. PyCapsule_Import will set an exception
    * if there's an error.
@@ -288,6 +290,13 @@ typedef struct {
       return -1;
     }
 
+    /* Imports the xbob.blitz C-API */
+    if (import_xbob_io() < 0) {
+      PyErr_Print();
+      PyErr_SetString(PyExc_ImportError, "xbob.io failed to import");
+      return -1;
+    }
+
     /* If you get to this point, all is good */
     return 0;
 
diff --git a/xbob/learn/activation/main.cpp b/xbob/learn/activation/main.cpp
index a2d929c63fc331ad46e24c94a17411aff9f133c1..7dc7afbfba3b7e190c565a2ab0f8ca8e70e2d084 100644
--- a/xbob/learn/activation/main.cpp
+++ b/xbob/learn/activation/main.cpp
@@ -11,8 +11,8 @@
 #ifdef NO_IMPORT_ARRAY
 #undef NO_IMPORT_ARRAY
 #endif
-#include <xbob.blitz/capi.h>
 #include <xbob.io/api.h>
+#include <xbob.blitz/cleanup.h>
 
 static PyMethodDef module_methods[] = {
     {0}  /* Sentinel */
@@ -33,86 +33,59 @@ static PyModuleDef module_definition = {
 
 int PyXbobLearnActivation_APIVersion = XBOB_LEARN_ACTIVATION_API_VERSION;
 
-PyMODINIT_FUNC XBOB_EXT_ENTRY_NAME (void) {
+static PyObject* create_module (void) {
 
   PyBobLearnActivation_Type.tp_new = PyType_GenericNew;
-  if (PyType_Ready(&PyBobLearnActivation_Type) < 0) return
-# if PY_VERSION_HEX >= 0x03000000
-    0
-# endif
-    ;
+  if (PyType_Ready(&PyBobLearnActivation_Type) < 0) return 0;
 
   PyBobLearnIdentityActivation_Type.tp_base = &PyBobLearnActivation_Type;
-  if (PyType_Ready(&PyBobLearnIdentityActivation_Type) < 0) return
-# if PY_VERSION_HEX >= 0x03000000
-    0
-# endif
-    ;
+  if (PyType_Ready(&PyBobLearnIdentityActivation_Type) < 0) return 0;
 
   PyBobLearnLinearActivation_Type.tp_base = &PyBobLearnActivation_Type;
-  if (PyType_Ready(&PyBobLearnLinearActivation_Type) < 0) return
-# if PY_VERSION_HEX >= 0x03000000
-    0
-# endif
-    ;
+  if (PyType_Ready(&PyBobLearnLinearActivation_Type) < 0) return 0;
 
   PyBobLearnLogisticActivation_Type.tp_base = &PyBobLearnActivation_Type;
-  if (PyType_Ready(&PyBobLearnLogisticActivation_Type) < 0) return
-# if PY_VERSION_HEX >= 0x03000000
-    0
-# endif
-    ;
+  if (PyType_Ready(&PyBobLearnLogisticActivation_Type) < 0) return 0;
 
   PyBobLearnHyperbolicTangentActivation_Type.tp_base =
     &PyBobLearnActivation_Type;
-  if (PyType_Ready(&PyBobLearnHyperbolicTangentActivation_Type) < 0) return
-# if PY_VERSION_HEX >= 0x03000000
-    0
-# endif
-    ;
+  if (PyType_Ready(&PyBobLearnHyperbolicTangentActivation_Type) < 0) return 0;
 
   PyBobLearnMultipliedHyperbolicTangentActivation_Type.tp_base =
     &PyBobLearnActivation_Type;
   if (PyType_Ready(&PyBobLearnMultipliedHyperbolicTangentActivation_Type) < 0)
-    return
-# if PY_VERSION_HEX >= 0x03000000
-      0
-# endif
-      ;
-
+    return 0;
 
 # if PY_VERSION_HEX >= 0x03000000
   PyObject* m = PyModule_Create(&module_definition);
-  if (!m) return 0;
 # else
-  PyObject* m = Py_InitModule3(XBOB_EXT_MODULE_NAME, 
-      module_methods, module_docstr);
-  if (!m) return;
+  PyObject* m = Py_InitModule3(XBOB_EXT_MODULE_NAME, module_methods, module_docstr);
 # endif
+  if (!m) return 0;
+  auto m_ = make_safe(m);
 
   /* register some constants */
-  PyModule_AddIntConstant(m, "__api_version__",
-      XBOB_LEARN_ACTIVATION_API_VERSION);
-  PyModule_AddStringConstant(m, "__version__", XBOB_EXT_MODULE_VERSION);
+  if (PyModule_AddIntConstant(m, "__api_version__", XBOB_IO_API_VERSION) < 0) return 0;
+  if (PyModule_AddStringConstant(m, "__version__", XBOB_EXT_MODULE_VERSION) < 0) return 0;
 
   /* register the types to python */
   Py_INCREF(&PyBobLearnActivation_Type);
-  PyModule_AddObject(m, "Activation", (PyObject *)&PyBobLearnActivation_Type);
+  if (PyModule_AddObject(m, "Activation", (PyObject *)&PyBobLearnActivation_Type) < 0) return 0;
 
   Py_INCREF(&PyBobLearnIdentityActivation_Type);
-  PyModule_AddObject(m, "Identity", (PyObject *)&PyBobLearnIdentityActivation_Type);
+  if (PyModule_AddObject(m, "Identity", (PyObject *)&PyBobLearnIdentityActivation_Type) < 0) return 0;
 
   Py_INCREF(&PyBobLearnLinearActivation_Type);
-  PyModule_AddObject(m, "Linear", (PyObject *)&PyBobLearnLinearActivation_Type);
+  if (PyModule_AddObject(m, "Linear", (PyObject *)&PyBobLearnLinearActivation_Type) < 0) return 0;
 
   Py_INCREF(&PyBobLearnLogisticActivation_Type);
-  PyModule_AddObject(m, "Logistic", (PyObject *)&PyBobLearnLogisticActivation_Type);
+  if (PyModule_AddObject(m, "Logistic", (PyObject *)&PyBobLearnLogisticActivation_Type) < 0) return 0;
 
   Py_INCREF(&PyBobLearnHyperbolicTangentActivation_Type);
-  PyModule_AddObject(m, "HyperbolicTangent", (PyObject *)&PyBobLearnHyperbolicTangentActivation_Type);
+  if (PyModule_AddObject(m, "HyperbolicTangent", (PyObject *)&PyBobLearnHyperbolicTangentActivation_Type) < 0) return 0;
 
   Py_INCREF(&PyBobLearnMultipliedHyperbolicTangentActivation_Type);
-  PyModule_AddObject(m, "MultipliedHyperbolicTangent", (PyObject *)&PyBobLearnMultipliedHyperbolicTangentActivation_Type);
+  if (PyModule_AddObject(m, "MultipliedHyperbolicTangent", (PyObject *)&PyBobLearnMultipliedHyperbolicTangentActivation_Type) < 0) return 0;
 
   static void* PyXbobLearnActivation_API[PyXbobLearnActivation_API_pointers];
 
@@ -179,17 +152,17 @@ PyMODINIT_FUNC XBOB_EXT_ENTRY_NAME (void) {
 
   if (c_api_object) PyModule_AddObject(m, "_C_API", c_api_object);
 
-  /* imports the NumPy C-API */
-  import_array();
+  /* imports xbob.io C-API + dependencies */
+  if (import_xbob_io() < 0) return 0;
 
-  /* imports xbob.blitz C-API */
-  import_xbob_blitz();
+  Py_INCREF(m);
+  return m;
 
-  /* imports xbob.io C-API */
-  import_xbob_io();
+}
 
+PyMODINIT_FUNC XBOB_EXT_ENTRY_NAME (void) {
 # if PY_VERSION_HEX >= 0x03000000
-  return m;
+  return
 # endif
-
+    create_module();
 }