fixed memory write routine