Thorough refactoring.