Scientists find clues on how some stars shed their outer layers