implemented demux - hopefully the right way