I would like to see more comments inside this function for future maintainers.