Tons of refactoring