Oops, I ended up rewriting all this from scratch.  There are just a few lines of remnant code from `recfunctions.join_by()`.