Misc refactoring, perf updates.