writing decode function