Initial phase of major code cleanup and refactoring.