fixed errors in decode function