Template support and refactoring