improvements on file write

Improvements on file write