fix small bugs with write data to file