Refactor of Fix for #22232

This is a refactor of NathanRSmith's fix for ticket #22232