added smart computation of cluster statistic handling sparse matrices and using connected components algorithm