General cleanup. Minor speed optimizations.