Cherry picked fixes tested in master for 5.2