Fix decoding logic