improved handleHeaderState