Made averageVec more general