Fix averaging logic