General speed-up, clean-up, and bugfixes.