Fix bugs in templates