Template support and minor tweaks