adding debug log to write_header