memory usage optimizations for read and write operations

Not aligned with previous line.