Almost complete rewrite. Doc out of sync.