fix up file writing