Moved logging block to the top of the file.