Fixes #5272 - This is a clone of #5291

#5291 was inadvertently reverted by @richard67 - this re-instate its code...

No need for testing, I think...