Fix reverse_arcs function and add unit tests for it