Fixed countSpectra to generalize