         (aset M (inc i) (inc j) (int (min del ins sub)))))
     (aget M m n)))
 
-(defn rtdm-edit-distance-sim
-  [tree-1 tree-2 del-cost ins-cost sub-cost]
-  (let [t1-desc (tree-descendants tree-1)
-        t2-desc (tree-descendants tree-2)]
+(defn tree-edit-distance-link
+  "load trees and return their edit distance"
+  [link1 link2]
+  (let [t1 (load-tree link1)
+        t2 (load-tree link2)]
     (- 1
-       (/ (rtdm-edit-distance tree-1 tree-2 del-cost ins-cost sub-cost)
-          (+ (* (+ (count t1-desc) 1) del-cost)
-             (* (+ (count t2-desc) 1) sub-cost))))))
-
-(defn get-xml-tree-body
-  "Downloads a webpage and converts it to an org.w3.dom.Document"
-  [page-src]
-  
-  (let [cleaner        (new HtmlCleaner)
-        props          (.getProperties cleaner)
-        cleaner-props  (new CleanerProperties)
-        dom-serializer (new DomSerializer cleaner-props)
-        tag-node       (.clean cleaner page-src)]
-    
-    (.createDOM dom-serializer tag-node)))
-
-(defn rtdm-edit-distance-html
-  [pg1 pg2 del-cost ins-cost sub-cost]
-  (rtdm-edit-distance-sim
-   (get-xml-tree-body pg1)
-   (get-xml-tree-body pg2)
-   del-cost
-   ins-cost
-   sub-cost))
+       (/ (tree-edit-distance t1 t2 1 1 1)
+          (+ (tree-descendants t1)
+             (tree-descendants t2))))))

(ns crawler.tree-edit-distance
  (:use [clojure.pprint])
  (:import (org.htmlcleaner HtmlCleaner DomSerializer CleanerProperties)
           (org.w3c.dom Document)))

(defn init
  "Perform the correct initialization"

                     del-cost
                     ins-cost)

            sub (if (= c-i c-j)
                  (- sub-i
                     (* ins-cost c-j-desc)
                     (* del-cost c-i-desc))
                  (cond
                   (or (not (-> c-i :content (filter map?)))
                       (not (-> c-j :content (filter map?))))
                   (+ sub-i sub-cost)

                   (or (= (-> c-i :tag) (-> c-j :tag)))
                   (- sub-i (invert-cost c-i c-j del-cost ins-cost sub-cost))

                   :else
