                     }
 
                     if Settings.instance.autoArchiveArenaDeck &&
-                        strong.currentGameMode == .arena &&
-                        deck.isArena && deck.arenaFinished() {
-                        deck.isActive = false
+                        strong.currentGameMode == .arena && deck != nil &&
+                        deck!.isArena && deck!.arenaFinished() {
+                        deck!.isActive = false
                     }
                     
-                    deck.statistics.append(statistic)
+                    deck?.statistics.append(statistic)
                 }
                 strong.syncStats(deck: deck, statistic: statistic)
             } catch {


    private func saveMatch(rank: Int, note: String, playerClass: CardClass,
                           opponentName: String, opponentClass: CardClass, opponentRank: Int) {
        guard let currentDeck = self.currentDeck else {
            Log.info?.message("No deck, ignore statistic")
            return
        }

        DispatchQueue.main.async { [weak self] in
            guard let strong = self else { return }
            do {
                let realm = try Realm()
                guard let deck = realm.objects(Deck.self)
                    .filter("deckId = '\(currentDeck.id)'").first else {
                        Log.error?.message("Can not get deck")
                        return
                }

                let statistic = Statistic()
                statistic.opponentName = opponentName

                    startTime = Date()
                }

                let endTime = strong.gameEndDate ?? Date()

                statistic.duration = Int(endTime.timeIntervalSince1970
                    - startTime.timeIntervalSince1970)
