error handling for faulty spectra; more cleanup and tests