changed writing file from Sync to Async