Major rewrite of template system: