creating .dat file plus some update to the code