added logic to determine winner