wait function fixed