Implemented better support for logging and error handling.