I am not entirely clear what that function does, and when. Do you mind adding an explanation in the docstring?