Fix the test case code that failed to fail. Clean up some of the convoluted logic in Template