backport of #1080 to 0.6.x