Refactored read/write