refactor
prepare hdr, hdrlen beforehand