Some error capture and clean up of html