Further performance improvements.

Wow, we wrote a lot of slow code here.