fix for Python3 since it does not have reduce()