refactor and correct raw message decode. not tested.