           (recur l k c g (dec max-iterations))
         :else g))))
 
+(defn k-means-profile
+  [l k max-iterations]
+  (p :k-means (k-means l k max-iterations)))
+
 (def flame [[1.85 27.8] [1.35 26.65] [1.4 23.25] [0.85 23.05] [0.5 22.35] [0.65 21.35] [1.1 22.05] [1.35 22.65] [1.95 22.8] [2.4 22.45] [1.8 22] [2.5 21.85] [2.95 21.4] [1.9 21.25] [1.35 21.45] [1.35 20.9] [1.25 20.35] [1.75 20.05] [2 20.6] [2.5 21] [1.7 19.05] [2.4 20.05] [3.05 20.45] [3.7 20.45] [3.45 19.9] [2.95 19.5] [2.4 19.4] [2.4 18.25] [2.85 18.75] [3.25 19.05] [3.95 19.6] [2.7 17.8] [3.45 18.05] [3.8 18.55] [4 19.1] [4.45 19.9] [4.65 19.15] [4.85 18.45] [4.3 18.05] [3.35 17.3] [3.7 16.3] [4.4 16.95] [4.25 17.4] [4.8 17.65] [5.25 18.25] [5.75 18.55] [5.3 19.25] [6.05 19.55] [6.5 18.9] [6.05 18.2] [5.6 17.8] [5.45 17.15] [5.05 16.55] [4.55 16.05] [4.95 15.45] [5.85 14.8] [5.6 15.3] [5.65 16] [5.95 16.8] [6.25 16.4] [6.1 17.45] [6.6 17.65] [6.65 18.3] [7.3 18.35] [7.85 18.3] [7.15 17.8] [7.6 17.7] [6.7 17.25] [7.3 17.25] [6.7 16.8] [7.3 16.65] [6.75 16.3] [7.4 16.2] [6.55 15.75] [7.35 15.8] [6.8 14.95] [7.45 15.1] [6.85 14.45] [7.6 14.6] [8.55 14.65] [8.2 15.5] [7.9 16.1] [8.05 16.5] [7.8 17] [8 17.45] [8.4 18.1] [8.65 17.75] [8.9 17.1] [8.4 17.1] [8.65 16.65] [8.45 16.05] [8.85 15.35] [9.6 15.3] [9.15 16] [10.2 16] [9.5 16.65] [10.75 16.6] [10.45 17.2] [9.85 17.1] [9.4 17.6] [10.15 17.7] [9.85 18.15] [9.05 18.25] [9.3 18.7] [9.15 19.15] [8.5 18.8] [11.65 17.45] [11.1 17.65] [10.4 18.25] [10 18.95] [11.95 18.25] [11.25 18.4] [10.6 18.9] [11.15 19] [11.9 18.85] [12.6 18.9] [11.8 19.45] [11.05 19.45] [10.3 19.4] [9.9 19.75] [10.45 20] [13.05 19.9] [12.5 19.75] [11.9 20.05] [11.2 20.25] [10.85 20.85] [11.4 21.25] [11.7 20.6] [12.3 20.45] [12.95 20.55] [12.55 20.95] [12.05 21.25] [11.75 22.1] [12.25 21.85] [12.8 21.5] [13.55 21] [13.6 21.6] [12.95 22] [12.5 22.25] [12.2 22.85] [12.7 23.35] [13 22.7] [13.55 22.2] [14.05 22.25] [14.2 23.05] [14.1 23.6] [13.5 22.8] [13.35 23.5] [13.3 24] [7.3 19.15] [7.95 19.35] [7.7 20.05] [6.75 19.9] [5.25 20.35] [6.15 20.7] [7 20.7] [7.6 21.2] [8.55 20.6] [9.35 20.5] [8.3 21.45] [7.9 21.6] [7.15 21.75] [6.7 21.3] [5.2 21.1] [6.2 21.95] [6.75 22.4] [6.15 22.5] [5.65 22.2] [4.65 22.55] [4.1 23.45] [5.35 22.8] [7.4 22.6] [7.75 22.1] [8.5 22.3] [9.3 22] [9.7 22.95] [8.8 22.95] [8.05 22.9] [7.6 23.15] [6.85 23] [6.2 23.25] [5.7 23.4] [5.1 23.55] [4.55 24.15] [5.5 24] [6.1 24.05] [6.5 23.6] [6.75 23.95] [7.3 23.75] [8.3 23.4] [8.9 23.7] [9.55 23.65] [10.35 24.1] [7.95 24.05] [3.95 24.4] [3.75 25.25] [3.9 25.95] [4.55 26.65] [5.25 26.75] [6.5 27.6] [7.45 27.6] [8.35 27.35] [9.25 27.2] [9.95 26.5] [10.55 25.6] [9.9 24.95] [9.2 24.5] [8.55 24.2] [8.8 24.8] [9.2 25.35] [9.55 26.05] [9.05 26.6] [8.8 25.8] [8.15 26.35] [8.05 25.8] [8.35 25.2] [7.9 25.3] [8.05 24.7] [7.3 24.4] [7.55 24.85] [6.85 24.45] [6.25 24.65] [5.55 24.5] [4.65 25.1] [5 25.55] [5.55 26.1] [5.55 25.25] [6.2 25.2] [6.8 25.05] [7.4 25.25] [6.65 25.45] [6.15 25.8] [6.5 26.1] [6.6 26.6] [7.7 26.65] [7.5 26.2] [7.5 25.65] [7.05 25.85] [6.9 27.15] [6.15 26.9]])
 (def R15 [[9.802 10.132] [10.35 9.768] [10.098 9.988] [9.73 9.91] [9.754 10.43] [9.836 9.902] [10.238 9.866] [9.53 9.862] [10.154 9.82] [9.336 10.456] [9.378 10.21] [9.712 10.264] [9.638 10.208] [9.518 9.956] [10.236 9.91] [9.4 10.086] [10.196 9.746] [10.138 9.828] [10.062 10.26] [10.394 9.984] [10.284 10.348] [9.706 9.978] [9.906 10.588] [10.356 9.198] [9.954 9.704] [9.796 10.378] [10.386 10.608] [10.41 9.912] [10.172 10.598] [10.286 9.712] [9.932 10.234] [10.298 9.948] [10.352 9.932] [9.848 10.328] [10.514 10.498] [9.944 9.934] [9.92 10.022] [9.908 10.606] [10.182 9.99] [10.256 9.25] [12.04 10.028] [12.082 10.044] [12.4 10.156] [11.988 9.926] [12.34 9.918] [12.228 9.978] [12.348 10.488] [12.044 9.358] [11.736 10.122] [12.35 9.798] [11.246 10.122] [12.276 10.99] [12.374 10.018] [12.53 10] [12.27 9.792] [12.364 10.176] [12.458 10.18] [11.952 9.682] [11.772 9.924] [11.502 10.008] [12.134 9.482] [11.628 10.286] [12.064 9.616] [11.906 9.82] [11.736 10.29] [12.114 10.904] [11.59 9.712] [12.648 9.814] [12.164 11.018] [12.22 9.796] [11.846 9.634] [11.808 10.058] [12.096 9.846] [11.594 10.078] [12.252 9.938] [11.998 9.676] [11.894 10.012] [12.274 9.936] [12.176 10.364] [12.104 10.388] [11.372 11.466] [10.94 11.482] [11.084 11.554] [11.232 11.374] [11.22 11.64] [10.962 11.75] [11.014 11.746] [11.524 10.982] [11.012 11.364] [11.2 11.062] [11.626 11.894] [11.23 11.728] [11.144 11.91] [11.106 11.868] [11.53 11.918] [11.21 11.114] [10.746 11.702] [11.154 11.692] [11.412 11.924] [10.948 11.532] [10.988 12.298] [10.96 11.392] [11.656 11.346] [11.178 12.062] [11.368 11.56] [11.264 11.724] [11.554 11.576] [10.974 11.114] [11.12 11.634] [11.51 12.052] [10.95 11.402] [11.864 12.406] [11.198 10.854] [11.65 11.496] [11.248 11.722] [11.602 11.888] [11.424 11.454] [11.312 11.718] [10.736 11.68] [11.56 11.798] [10.028 12.268] [9.282 11.976] [9.178 11.53] [9.954 12.398] [9.622 11.558] [9.914 11.844] [9.07 11.092] [10.578 11.354] [9.582 12.14] [9.622 11.528] [9.35 11.71] [10.234 11.974] [8.986 12.31] [9.438 12.11] [9.592 12.012] [9.666 11.88] [9.364 12.012] [9.71 11.772] [9.992 11.836] [9.916 12.028] [9.382 12.226] [9.808 12.23] [9.272 12.152] [9.392 11.18] [9.28 11.976] [9.848 11.632] [9.322 11.514] [9.718 11.95] [9.12 11.76] [8.978 12.37] [10.072 12.202] [9.966 11.822] [9.506 11.648] [9.702 11.536] [9.45 11.96] [9.916 11.962] [9.96 11.538] [9.014 11.744] [9.024 11.846] [10.296 11.61] [7.87 10.838] [8.164 10.534] [8.214 10.62] [8.166 10.698] [8.05 10.746] [7.978 11.13] [8.08 10.992] [8.472 11.082] [8.494 10.584] [8.354 10.38] [8.096 10.714] [7.882 10.832] [7.908 11.346] [7.814 10.872] [8.28 10.104] [8.082 10.676] [8.068 10.118] [8.116 10.698] [8.042 10.79] [8.096 10.878] [8.124 10.932] [8.632 11.124] [8.27 10.716] [7.622 10.148] [8.198 11.398] [8.582 11.064] [7.942 11.076] [8.004 10.574] [8.504 11.378] [8.118 11.012] [7.874 11.296] [7.668 10.924] [7.966 10.72] [7.94 10.996] [7.988 11.228] [8.164 11.112] [8.386 10.772] [8.248 10.994] [8.286 10.734] [8.224 10.316] [7.976 9.578] [7.876 8.796] [8.172 9.01] [8.068 9.202] [8.416 8.654] [8.71 8.458] [8.056 8.434] [7.304 9.266] [8.118 8.608] [7.616 9.446] [8.092 8.956] [8.368 8.968] [8.022 9.334] [8.32 9.062] [7.832 8.952] [7.704 8.672] [8.236 9.108] [8.37 8.904] [8.352 8.896] [8.046 9.228] [7.71 9.538] [8.534 8.55] [7.996 9.172] [8.046 9.204] [8.622 9.174] [7.776 8.898] [8.226 9.038] [7.904 9.194] [7.874 8.856] [7.992 8.952] [8.262 9.468] [8.088 9.294] [8.034 9.792] [8.352 9.016] [7.85 9.334] [8.404 9.366] [7.892 8.808] [8.202 9.232] [7.668 9.026] [8.242 9.308] [9.432 8.61] [10.066 8.19] [9.146 8.044] [9.662 7.866] [9.6 7.874] [8.618 8.552] [9.334 7.658] [9.424 7.83] [8.892 8.166] [9.386 7.746] [9.878 8.054] [9.558 7.948] [9.222 8.002] [9.52 8.282] [9.76 7.932] [9.568 8.052] [9.736 7.552] [9.584 8.478] [9.358 8.242] [9.404 7.79] [9.458 8.54] [9.482 7.766] [8.844 8.024] [9.29 8.472] [9.274 7.566] [9.11 8.014] [9.542 7.688] [9.432 8.122] [9.786 8.066] [9.382 7.664] [9.404 8.228] [9.146 8.158] [9.622 8.004] [10.286 7.892] [9.43 7.676] [9.44 8.058] [9.788 7.684] [9.586 7.91] [9.694 7.448] [9.576 7.866] [11.442 8.688] [11.466 8.558] [10.674 8.936] [11.23 8.126] [11.614 8.588] [11.59 8.496] [11.536 7.586] [11.638 8.266] [11.16 8.43] [10.904 8.532] [11.284 8.742] [11.25 8.192] [10.84 8.218] [11.798 8.836] [11.51 8.094] [10.932 7.796] [11.404 8.206] [11.088 8.326] [11.334 8.17] [11.272 8.394] [11.59 8.408] [11.212 8.516] [11.566 8.024] [11.246 8.584] [11.252 8.566] [10.78 8.294] [11.04 8.322] [11.198 7.886] [11.168 8.262] [11.88 8.08] [11.356 8.586] [11.182 8.342] [10.836 8.664] [11.696 8.906] [11.282 8.28] [10.718 8.534] [10.444 8.684] [11.124 8.618] [11.392 8.94] [11.212 8.308] [16.674 9.638] [16.162 10.302] [16.612 10.218] [16.1 9.702] [16.404 10.072] [15.93 10.106] [16.128 9.888] [16.41 10.188] [15.982 9.92] [16.224 10.02] [16.296 9.458] [16.586 10.174] [16.314 10.716] [16.278 9.452] [16.622 9.652] [16.22 9.494] [16.626 10.162] [16.982 10.596] [16.27 10.128] [16.202 9.7] [16.532 9.776] [17.124 9.726] [16.47 9.698] [16.004 10.28] [16.366 9.796] [16.268 9.522] [16.13 9.748] [16.67 10.498] [16.488 10.542] [16.57 10.21] [16.456 10.112] [16.482 9.986] [16.584 9.754] [16.1 9.93] [16.226 9.67] [16.448 9.566] [16.572 9.624] [16.436 9.41] [16.502 9.98] [16.418 9.966] [14.362 14.644] [14.138 14.63] [14.064 15.072] [13.692 14.958] [14.238 15.296] [13.73 15.128] [13.952 14.868] [13.986 14.77] [13.916 14.996] [13.874 14.954] [14.168 15.276] [14.278 15.152] [14.098 14.9] [13.764 15.212] [13.948 14.218] [14.13 14.838] [13.362 14.932] [13.546 14.844] [14.13 15.11] [13.816 14.602] [14.386 14.686] [13.786 14.726] [14.204 14.822] [13.856 15.206] [14.074 14.384] [13.68 14.988] [14.204 14.976] [13.388 15.39] [13.708 15.048] [14.114 15.366] [14.4 15.04] [14.194 15.04] [13.888 15.436] [13.958 15.322] [13.922 14.802] [13.652 14.602] [14.294 14.996] [13.81 14.526] [13.408 15.34] [13.834 14.778] [8.826 16.474] [8.33 16.488] [8.468 16.378] [8.904 15.846] [8.662 16.354] [8.684 16.776] [8.33 16.066] [8.904 16.402] [8.778 16.486] [8.81 16.458] [8.398 16.576] [8.542 15.918] [9.064 16.456] [9.152 16.094] [8.614 15.908] [8.566 17.012] [8.12 16.11] [8.844 16.026] [8.398 16.282] [8.808 15.59] [8.502 16.166] [8.942 16.19] [8.376 16.112] [8.518 15.84] [8.878 16.004] [8.582 16.774] [8.248 16.154] [8.588 16.24] [8.706 16.374] [8.524 16.392] [8.458 16.452] [8.83 16.36] [8.616 16.112] [8.844 16.362] [8.468 15.928] [8.62 16.674] [8.974 16.53] [8.826 16.084] [8.104 15.962] [8.386 16.24] [4.576 12.878] [4.46 13.16] [3.632 12.862] [4.238 12.506] [4.348 13.268] [3.788 12.372] [4.19 12.772] [3.86 12.706] [3.978 13.308] [4.336 12.854] [4.218 13.03] [4.25 13.002] [4.334 13.06] [4.654 12.566] [4.38 12.792] [3.968 13.016] [4.614 12.526] [3.95 12.67] [4.038 12.67] [4.426 12.238] [4.066 12.514] [4.248 12.392] [4.61 12.95] [4.328 12.99] [4.5 12.522] [4.176 12.71] [4.492 12.464] [4.134 12.834] [4.316 12.764] [4.454 12.084] [4.052 12.934] [4.26 13.118] [4.058 13.718] [4.24 12.626] [3.838 12.232] [4.128 13.4] [3.764 12.38] [4.424 13.186] [4.234 12.994] [5.13 13.296] [3.9 6.742] [3.994 7.206] [4.278 7.222] [4.172 6.848] [3.882 6.894] [3.936 6.994] [4.162 6.87] [3.762 7.1] [4.256 7.612] [4.55 6.822] [4.062 6.984] [4.026 7.23] [4.364 7.184] [4.292 7.208] [4.288 6.91] [4.018 7.062] [4.07 7.104] [4.548 7.654] [4.402 7.082] [3.692 7.49] [4.888 7.194] [4.456 7.146] [4.732 7.154] [4.088 7.212] [4.502 6.928] [3.402 7.434] [4.246 6.692] [4.166 7.256] [4.852 6.83] [4.398 7.428] [5.016 7.054] [4.25 6.76] [3.738 7.082] [4.254 7.264] [4.122 7.238] [3.878 7.232] [4.55 7.29] [4.03 7.126] [4.412 7.022] [4.276 7.244] [8.376 3.788] [8.81 3.864] [8.218 3.548] [8.374 3.748] [8.102 4.3] [8.386 3.952] [8.858 3.274] [8.884 3.504] [8.294 3.38] [8.38 3.178] [8.738 4.294] [9.1 3.84] [9.086 3.6] [8.616 3.45] [8.624 3.698] [8.632 3.82] [8.286 3.704] [8.816 3.58] [8.722 3.854] [8.298 3.378] [9.014 4.034] [8.87 3.554] [8.562 3.662] [8.6 3.828] [8.94 3.836] [8.768 4.32] [8.838 3.926] [8.288 3.466] [8.652 3.782] [8.376 3.956] [7.724 3.414] [8.374 4.136] [8.6 3.712] [9.026 3.788] [8.534 3.252] [8.874 3.602] [8.796 3.888] [8.592 3.988] [8.98 4.014] [8.562 3.856] [13.894 4.16] [14.278 5.26] [14.364 4.748] [14.108 4.918] [13.998 5.498] [14.4 5.296] [14.3 5.368] [13.958 5.35] [13.842 4.984] [13.85 4.246] [13.978 5.356] [14.366 5.104] [14.272 4.94] [14.336 5.176] [14.744 5.248] [14.306 5.06] [13.986 5.05] [14.44 5.33] [14.004 4.92] [13.332 4.592] [14.218 5.544] [14.154 4.768] [13.468 4.92] [13.67 5.406] [13.664 5.016] [14.12 4.87] [13.836 4.51] [14.204 5.064] [14.004 5.228] [13.266 4.858] [13.668 5.34] [14.528 4.812] [14.318 4.592] [14.018 5.182] [14.37 4.884] [14.198 4.804] [14.32 4.59] [13.636 5.218] [14.41 4.656] [14.02 5.614]])
 
 (defn -main
   "Main function for k-means"
   [& args]
-  (let [c (k-means R15 8 100)]
-    (spit "k-means.txt" c)))
+  ; (profile :info :Arithmetic (k-means-profile (make-vector-rand 20000) 2 100)))
+  (let [c (profile :info :Arithmetic (k-means (make-vector-rand 40000) 7 100)) => "Done"]
+    (spit "k-means.txt" c)) (shutdown-agents))

  (cond
    (<= n 0) c
    :else
      (recur (dec n) (conj c [(rand-int 5000) (rand-int 5000)])))))

(defn make-vector
  "create a vector containing n cols"

(defn k-means
  "Perform the actual k-means"
  ([l k max-iterations]
    (k-means l k (p :choose-initial-centroids (choose-initial-centroids l k)) (make-vector k) max-iterations))
  ([l k c g max-iterations]
    (let [t c g (p :cluster (cluster g l c)) c (p :mean-centroids (mean-centroids g))]
      (println "Iteration" (- 100 max-iterations) c)
      ; (println (still-moving? t c))
      (cond
        (> 0 max-iterations) g
