Some more refactoring, still needs some more work