backport PR #507