Fix some bugs in the decoder