Made getUndirectedDegree more efficient