modified program to handle headers with varying widths