Automated template refactorings