Switch to simpler version of inverse_edge

As per the discussion in #41, this re-implements `inverse_edge` in a way that is simpler and more efficient.