refactoring for writer.