redesigned decoding flow, based on harsh idea :)