added wait() polling function