Begin refactoring internal code.
More work on refactoring.