Closed loop control of laser welding using an optical spectroscopic sensor for Nd:YAG and CO2 lasers