                 }
                 self.counter = 30000
                 // --------------------------
-                bulk_ngrams_insert = String(bulk_ngrams_insert.characters.dropLast(2))+";"
-                _ = try db.run(bulk_ngrams_insert)
+                var ngrams_query = bulk_ngrams_insert
+                for i in 0..<ngrams.count {
+                    ngrams_query.append(ngrams[i])
+                    
+                    if(i % 1000 == 0) {
+                        ngrams_query = String(ngrams_query.characters.dropLast(2))+";"
+                        _ = try db.run(ngrams_query)
+                        ngrams_query = bulk_ngrams_insert
+                    }
+                }
                 
-                bulk_containers_insert = String(bulk_containers_insert.characters.dropLast(2))+";"
-                _ = try db.run(bulk_containers_insert)
+                var containers_query = bulk_containers_insert
+                for i in 0..<containers.count {
+                    containers_query.append(containers[i])
+                    
+                    if(i % 1000 == 0) {
+                        containers_query = String(containers_query.characters.dropLast(2))+";"
+                        _ = try db.run(containers_query)
+                        containers_query = bulk_containers_insert
+                    }
+                }
                 // --------------------------
                 self.dbCreated = true
             }

                    }
                    
                    if !ngrams_added.contains(insertNgram) {//result! == 0 {
                        bulk_ngrams_insert.append("(\"\(insertNgram)\",\(insert_n),\(freq)), ")
                        bulk_containers_insert.append("(\"Default\",\"\(insertNgram)\",\(insert_n),\(freq)), ")

                        ngrams_added.insert(insertNgram)
                    }

                var ngrams_added = Set<String>()
                var bulk_ngrams_insert = "INSERT INTO Ngrams (gram, n, frequency) VALUES "
                var bulk_containers_insert = "INSERT INTO Containers (profile, ngram, n, frequency) VALUES "
                
                var ngrams = [String]()
                var containers = [String]()
                
                // Populate the Ngrams table and Container table with words
                for word in allWords {
                    if word == "" || word == " " {
