Correctly getting count of connected components