Memory reading/writing fixes