refactored getEdges funciton