Rebased and redocumented version of PR #744