Move header calculation to an externally callable function.