Separate header parsing logic into a utility function.
Fix exception message.