Improve efficiency of onnxscript.rewriter, finish important TODOs and refactor for readability. Add documentation where appropriate.