Even more refactoring, because it's still fun