Added a better version of triple_sum