Document decode function