write out files at end