Fix use of hdr.delivery_tag instead of just hdr and refactor