I'm not sure what this function does, even after reading it. Can you add a comment explaining why it's necessary?