Backport PR 527 to 1.8.x