fix writeout of memery