Refactored to use Jinja templates