validate the html fragments and re-organize them