Rewrote rewrite function using already existing utilities.
Added test_issue_8430 to test_integrals.py.