fixed decode function