Added a wait function