changed averaging logic