Created wait function