updated decode function