This is a big rewrite. The pull request is not ready yet; this pull request is only a place to follow its progress.