Merged #4743 by hand.