added writing to an output file