Code refactoring and performance improvements

Optimized and avoided extensive DOM manipulations, now parse+repaint is
~%150 faster.
Code is now more modular and ready for further development.
Escape HTML while inserting DOM

HTML is now escaped.