further optimized the header computation