Use local_async to submit jobs, add structure and options to wait for jobs to complete.  Also allow credentials to be passed as parameters.