backport patch from master