refactored insertHeader method