Updated hw0.cpp: able to handle more connector cases