Implementation of sum simplified by having sum in a special class