what causes a nebula to collapse into a dense mass?