A few minor performance improvements.

Just a few changes to avoid unnecessary object creation and DOM calculations. I didn't test any of this, but the changes are fairly straightforward.