Refactor template renderer monkeypatching