       // We use the index here as the identifier would have changed. The index
       // gives us a good guess for finding the corresponding segment in the new
       // trip.
-      let segmentIndex = SegmentCardsInfo.cardsInfo(ofCardAtIndex: currentPageIndex, in: segmentCards)?.segmentIndex
-      let newSegment = cardSegments.first(where: { $0.index == segmentIndex }) ?? cardSegments.first!
+      let cardInfo = SegmentCardsInfo.cardsInfo(ofCardAtIndex: currentPageIndex, in: segmentCards)
+      let newSegment = cardSegments.first(where: { $0.index == cardInfo?.segmentIndex }) ?? cardSegments.first!
       
       do {
         let newCard = try TKUITripModeByModeCard(

        )
        newCard.style = self.style
        newCard.modeByModeDelegate = self.modeByModeDelegate
        controller?.swap(for: newCard, animated: true)
      } catch {
        TKLog.warn("Could not rebuild due to \(error)")
      }

  fileprivate struct SegmentCardsInfo {
    let segmentIndex: Int
    let segmentIdentifier: String?
    let segmentMode: TKUISegmentMode
    let cards: [(TGCard, TKUISegmentMode)]
    let cardsRange: Range<Int>
    
