 		   old-rhs-tuple (.rhs-tuple old-lhs-entry)
 		   old-extant (.extant old-lhs-entry)
 		   old-datum (.element old-lhs-entry)
-		   new-rhs-tuple (update-rhs-tuple old-lhs old-rhs-tuple new-lhs rhs-indeces rhs-immutables)
+		   [new-rhs-tuple new-rhs-indeces] (update-rhs-tuple old-lhs old-rhs-tuple new-lhs old-rhs-indeces rhs-immutables)
 		   dummy (info " update-rhs: new-lhs-tuple:" new-rhs-tuple)
 		   new-datum nil ;; TODO
 		   new-lhs-entry (LHSEntry. true (inc old-version) new-lhs new-rhs-tuple new-datum)
-		   new-lhs-index (assoc old-lhs-index lhs-pk new-lhs-entry)
-		   new-rhs-indeces (update-rhs-indeces old-rhs-indeces)] ;;TODO
+		   new-lhs-index (assoc old-lhs-index lhs-pk new-lhs-entry)]
 	       (info ["  update-lhs: version accepted" old-lhs-entry "->" new-lhs-entry])
 	       [new-lhs-index
 		new-rhs-indeces

	       (info ["  update-lhs: version rejected" lhs-pk])
	       ;; ignore this update - version is superceded
	       [old-lhs-index old-rhs-indeces old-insertions old-alterations old-deletions])))
	 (let [new-rhs-tuple (update-rhs-tuple nil nil new-lhs old-rhs-indeces rhs-immutables)
	       new-datum nil
	       new-lhs-index (assoc old-lhs-index lhs-pk (LHSEntry. true 0 new-lhs new-rhs-tuple new-datum))
	       new-rhs-indeces old-rhs-indeces] ;TODO
	   (info ["  inserting" lhs-pk])
	   ;; add a new entry
	   ;; update corresponding rhses - TODO


;; h/w immutables into fn - slower to carry them as args with every call

;; outputs [rhs-tuple rhs-indeces]
(defn update-rhs-tuple [old-lhs old-lhs-rhs-tuple new-lhs old-rhs-indeces rhs-immutables]
  [(if old-lhs
     []
     (map
      (fn [rhs-index [_ _ _ lhs-fk-getters-list]]
	  (map
	   (fn [lhs-fk-getters]
	     (map
	      (fn [^Getter lhs-fk-getter] 
		(let [rhs-pk (.get lhs-fk-getter new-lhs)
		      ^RHSEntry old-rhs-entry (rhs-index rhs-pk)
		      dummy (info ["  found entry" rhs-pk "->" old-rhs-entry ":" rhs-index])
		      rhs (and old-rhs-entry (.rhs old-rhs-entry))
		      dummy (info ["  found datum" rhs-pk "->" rhs])
		      new-rhs-entry (RHSEntry. rhs (conj (.lhs-refs old-rhs-entry) rhs-pk))]
		  rhs))
	      lhs-fk-getters))
	   lhs-fk-getters-list))
      old-rhs-indeces
      rhs-immutables))
   old-rhs-indeces])

;; returns -> [mutable immutable insertions alterations deletions]
(defn update-lhs [[lhs-index rhs-indeces] [[^Getter lhs-pk-getter ^Getter lhs-version-getter ^Metadata$Comparator lhs-version-comparator] rhs-immutables] insertions alterations deletions]
