Backport of PR #589 to 0.9.x