working winning function.