Alternative fix to #3594

As suggested by @vtjnash