carl's patch for #3471 applied to 3.X