Applied patch bt @glebm: lines 2975/2976