code optimizations and fixes for external stylesheets