Cleaned up header and footer code into functions