Refactored code to decouple rendering pipeline from template object