added write_report function