Fix some bugs in decoder