Refactor out reader/writer into separate modules