backport upstream changes