Lots of JavaScript optimization