There is a loop here which runs even when logging is off, so inefficient :-)