Fixed some error reporting and error handling.