refactoring reader/writer to separate files