Store edge in dict
More refactor