Did some important things
Refactored template code