fix some bugs in templates