added optimized edge counter