more cleanups and a new function logMessage'