protected function cleanURLList($location, $result)
    {
        $URLs = $location['md-electronic-url'];

        if ($URLs) {
            // Figure out which URLs are duplicates and collect indexes of those to remove.
            $indexesToRemove = [];
            foreach ($URLs as $URLIndex => &$URLInfo) {
                $URLInfo['attrs']['originalPosition'] = $URLIndex;
                $URL = $URLInfo['values'][0];

                // Check for duplicates in the electronic-urls field.
                for ($remainingURLIndex = $URLIndex + 1; $remainingURLIndex < count($URLs); $remainingURLIndex++) {
                    $remainingURLInfo = $URLs[$remainingURLIndex];
                    $remainingURL = $remainingURLInfo['values'][0];
                    if ($URL == $remainingURL) {
                        // Two of the URLs are identical.
                        // Keep the one with the title if only one of them has one,
                        // keep the first one otherwise.
                        $URLIndexToRemove = $URLIndex + $remainingURLIndex;
                        if (!$URLInfo['attrs'] && $remainingURLInfo['attrs']) {
                            $URLIndexToRemove = $URLIndex;
                        }
                        $indexesToRemove[$URLIndexToRemove] = true;
                    }
                }
                // Check for duplicates among the DOIs.
                $DOIs = $result['md-doi'];
                if ($DOIs) {
                    foreach ($DOIs as $DOI) {
                        if (strpos($DOI['values'][0], $URL) !== false) {
                            $indexesToRemove[$URLIndexToRemove] = true;
                            break;
                        }
                    }
                }
            }

            // Remove the duplicate URLs.
            foreach (array_keys($indexesToRemove) as $index) {
                $URLs[$index] = false;
            }
            $URLs = array_filter($URLs);

            // Re-order URLs so those with explicit labels appear at the beginning.
            usort($URLs, [$this, 'URLSort']);
        }

        return $URLs;
    }