         n-cols (count (first data))
         start-vector (or start-vector (repeatv n-cols 1))
         ; XXX - this add extra cols to the start vector if we have new comments... should test
-        start-vector (into [] (concat start-vector (repeatv (- n-cols (count start-vector)) 1)))]
+        start-vector (matrix
+                       (concat start-vector
+                               (repeatv (- n-cols (dimension-count start-vector 0)) 1)))]
     (loop [iters iters start-vector start-vector last-eigval 0]
       (let [product-vector (xtxr data start-vector)
-            eigval (norm product-vector)
-            normed (ic.core/div product-vector eigval)]
+            eigval (length product-vector)
+            normed (normalise product-vector)]
         (if (or (= iters 0) (= eigval last-eigval))
           normed
           (recur (dec iters) normed eigval))))))

(defn pca-project [data pcs]
  "Apply the principal component projection specified by pcs to the data"
  ; Here we map each row of data to it's projection
  (mapv
    ; each projection is the map of the pcs to the dot of a pc and the data-row
    (fn [data-row] (mapv #(dot data-row %) pcs))
    data))



(defn proj-vec [xs ys]
  "This computes the projection of ys orthogonally onto the vector spanned by xs"
  (let [coeff (/ (dot xs ys) (dot xs xs))]
    (* coeff xs)))


(defn factor-matrix [data xs]
  "As in the Gram-Shmidt process; we can 'factor out' the vector xs from all the vectors in data,
  such that there is no remaining variance in the xs direction within the data."
  (matrix (mapv #(- % (proj-vec xs %)) data)))


(defn centered-data [data]
  (- data (mean data)))


; Will eventually also want to add last-pcs
