Applied patch by @glebm: lines 2975/2976