slightly more efficient edge counting