calculate_cluster_variance_optimized function

Optimized cluster variance calculation