Refactor error reporting.