Backport #978 to 0.9.x