Refactor rm_request() a bit. There is still more work to be done, but this refactor breaks out 700+ lines into subfunctions that should be fairly easily unit testable.