Add connected component pruning, fixes weights assignment