Backport #202 to 3.x