completely redo close and writefile