Optimizations and html validation fixes