Add support for waiting for jobs.  Fix a problem with inlist optimization