refactored writing