added writing to output