fixed formula for connected components