Cleanup and minor refactoring.