proper wait function