Fix bug in connected components