completed checkwinner function