Improved template engine's logic.