Finalized write_output()