Replaced sum() with library method