implemented winner detection