added endgame logic and cleaned up some methods