finished refactoring optional header function