Reworked logging and error handling
Rewroked error handling