I don't feel it's entirely obvious what this function does