added wait to handle switching