             (update-settlement-pop id-settlement 0)
             (update-biome-map)
             (record-event (str "Village " (.name s) " is now a ghost town") nil))
-          (when (and (> (.pop s) 500) (chance 0.1))
-            (println "Spawning a new village")
+          (when (and (> (.pop s) 500) (chance 0.15))
+            (spawn-new-village-from id-settlement)
             (update-biome-map)
             ))))))
 
-(def fastness 1000)
-
-(defn- create-tribe-in-game [game]
-  (let [id-tribe (.next-id game)
-        game (assoc game :next-id (inc id-tribe))
-        id-settlement (.next-id game)
-        game (assoc game :next-id (inc id-settlement))
-        language (generate-language)
-        name-tribe (.name language)
-        name-settlement (.name language)
-        pos (free-random-land)
-        settlement (Settlement. id-settlement name-settlement 100 id-tribe pos)
-        tribe (Tribe. id-tribe name-tribe language [id-settlement])
-        game (assoc-in game [:tribes id-tribe] tribe)
-        game (assoc-in game [:settlements id-settlement] settlement)]
-      (run-randomly (update-tribe-fun id-tribe) 3000 10000)
-      (run-randomly (update-settlement-fun id-settlement) (* fastness 3) (* fastness 10))
-      (record-event (str "Creating tribe " name-tribe) pos)
-      (record-event (str "Creating village " name-settlement) pos)
-      (update-biome-map)
-    game))
-
-(defn create-tribe []
-  (swap! game create-tribe-in-game))
+(defn get-next-id []
+  (let [next-id (.next-id @game)
+        _ (swap! game assoc :next-id (inc next-id))]
+    next-id))
+
+(defn- create-tribe []
+  (try
+    (let [id-tribe        (get-next-id)
+          id-settlement   (get-next-id)
+          language        (generate-language)
+          name-tribe      (.name language)
+          name-settlement (.name language)
+          pos             (free-random-land)
+          settlement      (Settlement. id-settlement name-settlement 100 id-tribe pos)
+          tribe           (Tribe. id-tribe name-tribe language [id-settlement])
+          _               (update-tribe tribe)
+          _               (update-settlement settlement)]
+          _               (assert (= settlement (get-settlement id-settlement)))
+          _               (assert (= tribe (get-tribe id-tribe)))
+        (run-randomly (update-tribe-fun id-tribe) 3000 10000)
+        (run-randomly (update-settlement-fun id-settlement) (* fastness 3) (* fastness 10))
+        (record-event (str "Creating tribe " name-tribe) pos)
+        (record-event (str "Creating village " name-settlement) pos)
+        (update-biome-map))
+    (catch AssertionError e (println "Create tribe: " (.getMessage e)))))
 
 ; --------------------------------------
 ; Game functions

    (run-every-n-seconds f n)))

(defn run-randomly [f min max]
  (future (Thread/sleep (+ min (rand-int (- max min))))
    (f)
    (run-randomly f min max)))

(defn init []
  (run-every-n-seconds pop-balancer 10))

                (.id s)
                acc)) nil settlements)))

(defn free-cell? [pos]
  (nil? (settlement-at pos)))

(defn land? [pos]
  (let [x (:x pos) y (:y pos)
        w (-> (get-world) .getDimension .getWidth)
        h (-> (get-world) .getDimension .getHeight)]
    (if (or (< x 0) (< y 0) (>= x w) (>= y h))
      false
      (let [ b (-> (get-world) .getBiome)
             biome (.get b (:x pos) (:y pos))]
        (not (= (.name biome) "OCEAN"))))))

(def fastness 1000)

(defn random-pos []
  (let [w (-> (get-world) .getDimension .getWidth)
