Performance tweaks.

Runs much faster now.