refactored to use sum()