Newbie - stack overflow in connected components