minor nitpick - can we move the `writer.close()` into a finally?