Removed code duplication and prevents mutating passed in header_fields