Updated sum function