refactored writer