Add template stuff
Improve code generation