added logic for determining winner