Reworked the error handling and added the log global