improve data logging logic