Use the flatten() function from stdlib instead of sum()

It's unknown from which module the sum() function comes, but it isn't working
for a lot of users.

So use the flatten() function from stdlib

This resolves the issue reported earlier