         i += 1
     }
 
-    let genetic = Genetic()
-
-    var pop = Population(size: allCities.count, initialize: true)
-    var tour = pop.getFittest()
-    print("Start: \(tour.getDistance())")
-
-    for i in 0..<5 {
-        pop = genetic.evolve(population: pop)
-        if i % 1 == 0 {
-            tour = pop.getFittest()
-            print("\(i + 1). \(tour.getDistance())")
-        }
-    }
-
-    tour = pop.getFittest()
-    print("End: \(tour.getDistance())")
-
+    backgroundQueue.async {
+        let genetic = Genetic()
+
+        var pop = Population(size: allCities.count, initialize: true)
+        var tour = pop.getFittest()
+        print("Start: \(tour.getDistance())")
+
+        for i in 0..<50 {
+            pop = genetic.evolve(population: pop)
+            if i % 1 == 0 {
+                tour = pop.getFittest()
+                print("\(i + 1). \(tour.getDistance())")
+            }
+        }
+
+        tour = pop.getFittest()
+        print("End: \(tour.getDistance())")
+        programSemaphore.signal()
+    }
+
+    programSemaphore.wait()
 }
 
 

            offset = 1
        }

        for i in offset..<population.size {
            let parent1 = select(from: population)
            let parent2 = select(from: population)
            let child = crossover(parent1: parent1, parent2: parent2)
            newPop[i] = child
        }

        for i in offset..<population.size {
            newPop[i] = mutate(tour: newPop[i])
        }

    }

    func crossover(parent1: Tour, parent2: Tour) -> Tour {
        var child = Tour()

        var start = Int(arc4random_uniform(UInt32(parent1.size)))
