added check for null when adding header