add missing writer.close()