work on handling error writing file.