Backports some fixes from cur_job