replaced for loop sum with generator