Set $result before the checks to avoid a notice.