Fix demux, add proper tests for demux