 (def next-state rest)
 
 (defn arrange-keyval! [state elem container]
-  (d/add-class! elem "arranged")
   (let [[key separator val] (d/children elem)]
     (arrange-element! state key container)
     (arrange-element! state val container)

        :else
          (recur (.-parentNode elem) container)))

(defn toggle! [elem container]
  (cond (d/has-class? elem "condensed")
        (arrange! elem container)
        (d/has-class? elem "arranged")
        (do (condense! elem (find-arranged-parent (.-parentNode elem)
                                                  container))
            (d/set-styles! elem {:display "block"}))))

(defn set-toggle-on-click! [elem container]
  (events/listen (d/single-node elem) "click"
                 (fn [event]
                   (loop [elem (.-target event)]
                     (when elem
                       (if (and (gdom/isElement elem)
                                (d/has-class? elem "collection")
                                (or (d/has-class? elem "condensed")
                                    (d/has-class? elem "arranged")))
                         (do (.stopPropagation event)
                             (.preventDefault event)
                             (toggle! elem container))
                         (recur (.-parentNode elem))))))))

                             :overflow "hidden"
                             :text-overflow "ellipsis"})))

(defn arrange-element! [state elem container]
  (remove-all-styles! elem)
  (d/set-styles! elem {:white-space "pre"})
  (when (overflow? elem container)
    (cond
     (d/has-class? elem "collection")
     (if (d/has-class? elem "condensed")
       (condense-collection! elem container)
       (arrange-collection! state elem container))
     (d/has-class? elem "keyval")
     (arrange-keyval! state elem container))))

(defn arrange! [elem container]
  (arrange-element! initial-arrange-state elem container))

(defn find-arranged-parent [elem container]
  (cond (= container elem)
