memory usage optimizations for read and write operations

We can merge this line with the previous line.