Fixed error logging and data logging code