separated headers and footers and redid php code to output mongo documents