With this last tweak, it looks installable.  Indentation is a mess,
but I'm not going to worry about that.  I'd rather avoid duplication
of code than worry about formatting.