New restructured version, not yet tested.