Major reorganization. Doesn't compile, but I'd better commit now before I lose it.