This is rather a mess, and includes a lot of detritus from
uncareful coding along the way.  I hope to clean it up and make it sensible in subsequent commits.