Add in averaging code