expanded average() to include deep iteration functionality