refactor demodulator