Some tweaks to how errors are raised and logging.