Document top-level bindings.

This is minimal documentation to help me find my way around this file.
Rename some local bindings.

This is preparing for lifting these bindings to the toplevel.
Lift local functions.