Changed get_edges to a pure subroutine, which made a huge difference.