refactor by extracting header and year printing