Writer refactored a bit