Fix pull request #2007

The fix for pull #2116 without reverting it.