fix file write bug