memory usage optimizations for read and write operations

Not aligned with previous line. We could also merge with previous line, since it doesn't our hard limit of 90 characters.