Huge refactoring.