added caching mechanism to cov:sq_dist