added end of game detection