Added Average function from pull request by MatthewSteeples