Fixed bugs in templates as detected by FindBugs in the generated code. refs #526