Optimization changes for read/write memory + minor test changes