Fixed some bugs in the logging loop.