Update templates and fix bugs