apply some of the backports from master here