             try! realm.write {
                 updatingDeck.name = deck.name
             }
+            
+            deckDBChanged = true
+            
         }else {
             DataManagerError.NoDeckWithGivenId
         }

    private var decks = [Deck]()
    // private var flashcards = [Flashcard]()
    private let realm = try! Realm()
    
    init(){
        // usuwanie tylko wtedy gdy jest internet i najpewniej nie w tym miejscu. Na razie ze względu na 
        // DummyData
        // TODO: relocate removeDecksFromDatabase() and check for internet connection
        removeDecksFromDatabase()
        
    }
    
    func decks(sorted:Bool )->[Deck] {
        
        // load all Deck from database to memory, if not loaded
        loadDecksFromDatabase()

        if (sorted){
            return decks.sort {

        return decks.copy()
    }
    
    // loading decks from Realm. Used for refresh after changing decks in db
    func loadDecksFromDatabase(forced: Bool = false) {
        
        if !decks.isEmpty || forced{
            decks.removeAll()
        }
        
        decks = realm.objects(Deck).toArray()
        // jako że załadowane talie z pamięci zgadzają się z tymi z bazy, to false
        deckDBChanged = false
    }
    
    func removeDecksFromDatabase() {
        try! realm.write {
            realm.deleteAll()
        }
        
        deckDBChanged = true
        
    }
    
    func deck(withId id:String)->Deck? {
