Bug fixes for templates