Another partial nexgen rewrite.

This a rewrite of the rewrite, actually.  Things are starting to prove
tricky, and we're pondering if all this faff is worth at all.