MDL-47064 Grades: Add comments to explain this tricky code.