Proposal for cleaning up the html for the gallery.  note: this is not tested. I might have forgotten to remove a closing tag somewhere, its mainly to give it a start.