Make sure the writers and output streams are always properly closed.