rolled my own connected components algorith but still stack overflows