This code is a few layer of abstraction stacked up on top
of each other, and they're hard to see all at the same time
because the file is pretty mixed up. As much as I try to avoid
code rearrangement to keep history, this one is long overdue.
A followup CL will cut out some of the layers, and the diff will be
much clearer what's going on with the code ordered with
callers near callees, as it is now.