Added unit tests for TemplateUtil and fixed some issues found in tests.