         vvec (for [npdgm newpdgms] (val npdgm))
         pmapvec (for [vgroup vvec] (for [vrow vgroup] (vec2map vrow)))
         ;; transform pmaps to hash-maps
-        prmaps (for [prmap pmapvec] (for [prmp prmap] (pstring2map prmp)))
-        pmaps (for [prmap prmaps] (apply conj prmap))
+        prmaps (for [prmap pmapvec] (for [prmp prmap] (pstring2maps prmp)))
+        ;;pmaps (for [prmap prmaps] (apply conj prmap))
+        pmaps (join-pmaps prmaps)
         headerset3 (clojure.string/replace headerset2 #"[\[\]\"]" "")
         heads (split (str headerset3) #" ")
         ;;headvec (for [pivot pivotlist] (vec-remove heads pivotlist))
         pivotnames (vec (for [pivot pivots] (nth heads pivot)))
         headvec (vec (remove (set pivotnames) heads))
         ;; set of lists of vaue-combination-terms
-        keylists (set (for [pmap pmaps] (keys pmap)))
+        keylists (vec (for [pmap pmaps] (keys pmap)))
         ;;keylists (set (keys pmap))
-        ;; why is replace necessary; none of deleted chars should be in keys
-        keystring (clojure.string/replace (str keylists) #"[#(){}]" "")
+        ;; replace seems to be ad hoc cluj; 
+        ;; only '[' and ']' appear in one-line paradigm keyvec (but should not)
+        ;; other deleted chars should not be in keys in the first place
+        keystring (clojure.string/replace (str keylists) #"[#(){}\[\]]" "")
         keyvec (split keystring #" ")
         ;; set of all value combinations, as strings, in the combined pdgms
         keyset (set keyvec)

        [:p "pivotnames: " (str pivotnames)]
        [:p "heads: " (str heads)]
        [:p "headvec: " (str headvec)]
        ;;[:p "prows: "  (str prows) [:pre prows]]
        ;;[:p "pcells: " (println (str pcells)) [:pre pcells]]
        [:p "pivot-map: " [:pre pivot-map]]
        ;;[:p "newpdgms: " [:pre newpdgms]]
        [:p "pvalvec: " (str pvalvec)]
        [:p "pdgmstr2: " [:pre pdgmstr2]]
        ;;[:p "vvec: " [:pre vvec]]
        ;;[:p "vvec: " (str vvec)]
        ;;[:p "pmapvec: " [:pre pmapvec]]
        ;;[:p "prmaps: " [:pre prmaps]]
        [:p "pmaps: " [:pre pmaps]]
        ;;[:p "keylists: " [:pre keylists]]
        ;;[:p "keystring: " [:pre keystring]]
        [:p "keyset: " [:pre keyset]]
        [:p "==========================="]]
      [:script {:src "js/goog/base.js" :type "text/javascript"}]

            pbody2 (clojure.string/replace pbody1 #" " "_")
            ]
        ;; add pdgm name to each row of pbody as first value
        (clojure.string/replace pbody2 #"\r\n(\S)" (str "\r\n" pnum  ",$1"))))))

(defn csv2pdgm
"Takes sorted n-col csv list with vectors of pnames and headers, and outputs n+1-col html table with first col for pname ref; cols are draggable and sortable."
