encapsulate these checks already in a function read_and_validate_header() that you pass the expected type