                 let firstTabTimestamp = firstTab.lastExecutedTime ?? firstTab.sessionData?.lastUsedTime ?? firstTab.firstCreatedTime ?? 0
                 let secondTabTimestamp = secondTab.lastExecutedTime ?? secondTab.sessionData?.lastUsedTime ?? secondTab.firstCreatedTime ?? 0
                 return firstTabTimestamp < secondTabTimestamp
+
+            } else if let firstSite = $0 as? Site, let secondSite = $1 as? Site {
+                let firstSiteATimestamp = TimeInterval.fromMicrosecondTimestamp(firstSite.latestVisit?.date ?? 0)
+                let secondSiteTimestamp = TimeInterval.fromMicrosecondTimestamp(secondSite.latestVisit?.date ?? 0)
+                return firstSiteATimestamp < secondSiteTimestamp
             } else {
                 fatalError("Error: We should never pass a type \(T.self) to this function.")
             }

            innerMetadataLoop: for (searchTerm, historyMetaList) in searchTermMetadata {
                if historyMetaList.contains(where: { metadata in
                    var stringURL: String = ""
                    if let item = item as? URL {
                        stringURL = item.absoluteString

                    } else if let item = item as? Tab, let url = item.lastKnownUrl?.absoluteString {
                        stringURL = url


class SearchTermGroupsManager {

    public static func getURLGroups(with profile: Profile, from urls: [Site], using ordering: ComparisonResult, completion: @escaping ([ASGroup<Site>]?, _ filteredItems: [Site]) -> Void) {
        getGroups(with: profile, from: urls, using: ordering, completion: completion)
    }

