 
         deckName.stringValue = deck!.name 
 
-        if RealmHelper.getDeck(with: deck!.deckId) != nil {
-            exists = true
+        if let deck = RealmHelper.getDeck(with: deck!.deckId) {
+			self.deck = deck
+			exists = true
         } else {
             Log.error?.message("Can not fetch deck")
         }

    func saveDeck(update: Bool) {
        guard let deck = deck, let cards = cards, cards.isValidDeck() else { return }
		
		RealmHelper.update(deck: deck, with: cards)
        RealmHelper.add(deck: deck, update: update)
        
        NotificationCenter.default.post(name: Notification.Name(rawValue: "reload_decks"),
                                        object: deck)

    @IBAction func save(_ sender: AnyObject) {
        guard let deck = deck, let cards = cards, cards.isValidDeck() else { return }

		if self.exists {
			RealmHelper.rename(deck: deck, to: deckName.stringValue)
		} else {
			deck.name = deckName.stringValue
		}
        self.saveDeck(update: exists)
    }

