pre-compute mean for speed