Update in response to discussion. Still untested and unsuitable for merge.