wrote low level de-multiplexing code. ragged but works