Improved template engine and added unit tests