Effects of low-Z and high-Z impurities on divertor detachment and plasma confinement