added thread safety to master and worker
fix two batch workflow bugs