fixed outfile handling