Fix bugs in templates.