Added code to handle 0 or 1 spectrum