fixed some bugs in templates