Backported Mikhail's 3cec23f to 3.3.x.