Fixes Ticket #16330

This PR fixes ticket #16330 and incorporates all changes requested in the comments.