a ton of refactoring