Extracted method to build header.