fix bugs to make template work