Refactoring a lot of stuff