Refactoring a bunch