Updated to handle reuse of header and footer on pages.