Rewritten with swig and better style