added checkwin logic