header logic more robust