Various tweaks, fixes and improved logging.