modified calculateCup2 function