Fixes and performance improvements to html engine