fix a write bug with multiple output files