refactored class structure so that both modulator and demodulator can use the same code