fixed memory write and read