Massive refactoring for fun