Some speed improvements from profiling.

These aren't huge, but they should help performance a bit.