checking already added edges with a set instead of a boolean hash for clarity