Refactor multiplayer function