Not a blocker to merging this code, but just as a note: this variable "transac," which  gets used by closure in the call to transform() below and then gets covered over by a redefinition inside the later call to each(), and then finally, nearly as a side effect, is used to commit the whole transaction, makes the code pretty hard to read. It suggests that this method should probably be broken up into two.