refactored page building to dynamically read header length