added basic write_document() function