c++ version of the jCluster code