added logging, writing the data file