Added logging and error reporting.