restuctured code to be able to print the header separately