Port 5d1f7c0, 227ad28, 99a2003, 19e343f, e7c7284, bca4833 and 46dd41f from internal repository