Code cleanup and better multiplayer support