move header copying logic to correct place