avg function: small refactoring to improve code reuse and fix possible
ArithmeticException on non distributed executions
Merge pull request #2625 from fabriziofortino/develop

avg function: small refactoring to improve code reuse and fix possible