more memory efficient writing