minor optimization to wait function