Created more efficient undirectedDegree method