Can you add some comments in this function explaining what's going on? I'm a bit lost.