Pulled out end game logic into its own function