Major refactoring, no tests pass