diff --git a/bob/learn/misc/old/ivector_trainer.cc b/bob/learn/misc/old/ivector_trainer.cc
index d98ed5076e02928c92491369f76624c0b2822ea6..8b964a832799ef492d6201b66d0bbfde4d7e4269 100644
--- a/bob/learn/misc/old/ivector_trainer.cc
+++ b/bob/learn/misc/old/ivector_trainer.cc
@@ -88,7 +88,7 @@ static boost::python::object ITB_getRng(EMTrainerIVectorBase& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/old/jfa_trainer.cc b/bob/learn/misc/old/jfa_trainer.cc
index 18d0299371a8d3d9635e2978818307aa658d97da..a5966e27b5c32718863253aed8e5695c55ce88d7 100644
--- a/bob/learn/misc/old/jfa_trainer.cc
+++ b/bob/learn/misc/old/jfa_trainer.cc
@@ -316,13 +316,13 @@ static boost::python::object isv_getRng(bob::learn::misc::ISVTrainer& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 static boost::python::object jfa_getRng(bob::learn::misc::JFATrainer& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/old/kmeans_trainer.cc b/bob/learn/misc/old/kmeans_trainer.cc
index 3a5838afb121dd15cac78ce5016e89a88344a921..4ef008bb01702da3555c8aa0f22b48fb6ae0fcc2 100644
--- a/bob/learn/misc/old/kmeans_trainer.cc
+++ b/bob/learn/misc/old/kmeans_trainer.cc
@@ -62,13 +62,13 @@ static boost::python::object KMTB_getRng(EMTrainerKMeansBase& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 static boost::python::object KMT_getRng(bob::learn::misc::KMeansTrainer& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/old/plda_trainer.cc b/bob/learn/misc/old/plda_trainer.cc
index 1c31059c9b2fe64664b845d0a4baa26fcd29b6e2..a9a9de3e24def7637fbf93e25c86253989955d01 100644
--- a/bob/learn/misc/old/plda_trainer.cc
+++ b/bob/learn/misc/old/plda_trainer.cc
@@ -98,7 +98,7 @@ static boost::python::object TB_getRng(EMTrainerPLDA& self){
   // create new object
   PyObject* o = PyBoostMt19937_Type.tp_alloc(&PyBoostMt19937_Type,0);
   reinterpret_cast<PyBoostMt19937Object*>(o)->rng = self.getRng().get();
-  return boost::python::object(boost::python::handle<>(o));
+  return boost::python::object(boost::python::handle<>(boost::python::borrowed(o)));
 }
 
 #include <boost/make_shared.hpp>
diff --git a/bob/learn/misc/test_jfa_trainer.py b/bob/learn/misc/test_jfa_trainer.py
index 5de6a46b26614adcb9e5f7256a88a08fddd50f72..7c3f4d4c3743593acb0fabc3bb84fe79de654941 100644
--- a/bob/learn/misc/test_jfa_trainer.py
+++ b/bob/learn/misc/test_jfa_trainer.py
@@ -11,10 +11,11 @@
 import numpy
 import numpy.linalg
 
+import bob.core.random
+
 from . import GMMStats, GMMMachine, JFABase, JFAMachine, ISVBase, ISVMachine, \
     JFATrainer, ISVTrainer
 
-from . import mt19937 as old_mt19937
 
 def equals(x, y, epsilon):
   return (abs(x - y) < epsilon).all()
@@ -266,7 +267,7 @@ def test_JFATrainInitialize():
   ## JFA
   jb = JFABase(ubm, 2, 2)
   # first round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   jt = JFATrainer(10)
   jt.rng = rng
   jt.initialize(jb, TRAINING_STATS)
@@ -275,7 +276,7 @@ def test_JFATrainInitialize():
   d1 = jb.d
 
   # second round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   jt.rng = rng
   jt.initialize(jb, TRAINING_STATS)
   u2 = jb.u
@@ -299,7 +300,7 @@ def test_ISVTrainInitialize():
   ## ISV
   ib = ISVBase(ubm, 2)
   # first round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   it = ISVTrainer(10)
   it.rng = rng
   it.initialize(ib, TRAINING_STATS)
@@ -307,7 +308,7 @@ def test_ISVTrainInitialize():
   d1 = ib.d
 
   # second round
-  rng = old_mt19937(0)
+  rng = bob.core.random.mt19937(0)
   it.rng = rng
   it.initialize(ib, TRAINING_STATS)
   u2 = ib.u
diff --git a/bob/learn/misc/test_kmeans_trainer.py b/bob/learn/misc/test_kmeans_trainer.py
index 8d47cf0b6f1995c62694a5ad89e1eb80218f8c67..9cf2ad3bddc537ba8ac8dc8d7306564ad7ab5956 100644
--- a/bob/learn/misc/test_kmeans_trainer.py
+++ b/bob/learn/misc/test_kmeans_trainer.py
@@ -15,7 +15,6 @@ from bob.io.base.test_utils import datafile
 
 from . import KMeansMachine, KMeansTrainer
 
-from . import mt19937 as old_mt19937
 
 def equals(x, y, epsilon):
   return (abs(x - y) < epsilon).all()
@@ -74,7 +73,7 @@ if hasattr(KMeansTrainer, 'KMEANS_PLUS_PLUS'):
     # C++ implementation
     machine = KMeansMachine(dim_c, dim_d)
     trainer = KMeansTrainer()
-    trainer.rng = old_mt19937(seed)
+    trainer.rng = bob.core.random.mt19937(seed)
     trainer.initialization_method = KMeansTrainer.KMEANS_PLUS_PLUS
     trainer.initialize(machine, data)
 
@@ -92,7 +91,7 @@ def test_kmeans_noduplicate():
   # Defines machine and trainer
   machine = KMeansMachine(dim_c, dim_d)
   trainer = KMeansTrainer()
-  trainer.rng = old_mt19937(seed)
+  trainer.rng = bob.core.random.mt19937(seed)
   trainer.initialization_method = KMeansTrainer.RANDOM_NO_DUPLICATE
   trainer.initialize(machine, data)
   # Makes sure that the two initial mean vectors selected are different