This adds the suggestion from @doekia in #6535
The new part is the last union. The rest is just better formatting.
I've not been able to live test this yet.
Closes #6535