Basic template code

not tested yet
Fix templates