Refactors to make things usable from python