Updated logging and error handling