add separate method for writing file