fixes a bug when an output file is specified