Refactor and add documentation for writers.
Add docs and refactor.