updated file.write block