added wait to Popen