Fixed a bug concerning closing HTML elements in foreign content
Added more tests (MathML and SVG)
Cont'd refactoring