new way to count number of connected components