Refactored header and foot code to a layout