Add exception handling and split out functions to better fit that handling.
Shuffle first header handling into a dedicated function