Heavy refactoring.