fix write to file