Add tests for Template-related classes

In this commit Ihave refactored the template classes to improve testability; adhere more to SRP and added tests to ensure that they work correctly