added wait to avoid race condition