Add swig teplater, refactor and setup code