Templating cleanup and helpers