It seems like there are different code paths for determining the GID depending on if the user is being created or is having their GID reassigned; is this intentional? If so, why?