More speedups and bug fixes.