Replaced for loop and replaced it with inject. Removed sum variable.