         return decks.copy()
     }
     
-    // loading decks from Realm. Use for refresh after changing decks in db
-    func loadDecksFromDatabase() {
-        
-        if !decks.isEmpty {
+    // 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()
-    }
-    
-    // remove all decks from database
+        // 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? {

    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 {

            realm.add(newDeck)
        }
        
        deckDBChanged = true
        
        return id
    }

