updated logic to not output empty headers