Fixed a bug in template copying