fixed bugs in decode code