fixes writing to memory