Partial sum implementation