Fix bug in connected components
Add more error message coverage