Refactor error handling to clear some warnings.