#17477 Fix problems, add comments, improve formatting
#19747 More tweaks
#19747 More fixes