added debugging statements. some cleanup. YI:--waveform generation code not touched.