Refactor runEdges() cleanly