several fixes, added templating support (swig)