refactoring edges array to map, remove indexOf