added support for self closing html tags, optimized code