Major refactor of templates