Refactor reader_header to remove duplicate code