added wait for termination