fix bugs in template