fixed the bug for centroid initialization and allocation