Completed the sum function