bug fix, flag to write output to file