Refactoring and fixed error in CheckGameOver function