finished sum function