Fix bug in template generation