Fixes for faster cor and cov

Fixes for #2311.