memory write fixes