Some major refactoring.