cherry pick Lucy's 5.1.0.x changes