Refactor some of the functionality in req_quejob and add some unit tests.