faster by precalculating averages