added wait function