fix bugs in templates