Refactoring and extracting generation code to Writer Absrtraction