fix problem with file writing