Refactor writer and reader classes