Fixed indexing issues in new averaging scheme