Major refactoring of demuxing