Move some code both reader and writer needs to a base class