made a documentwriter function which takes care of more boilerplate