Refactored sum operation