manually merge PR #797 and PR#808