fix bug in sum and product function