Replacement for #3940
Merge pull request #3963 from GrahamCampbell/4.1-fix

Replacement for #3940