Major refactoring.