Big refactoring, tests succeed