fix several template validation bugs