Added locals for template functions and added more tests.