Reworked the data logging code