Refactor get number of edges