refactored template renderer