A rough attempt at detecting headers, but currently commented out.  Fixed the encoding issue that was giving trouble.