added the modifications for the multiple demultiplexing case