refactoring and addition of custom waveforms, plus some optimization and a couple other little fixes