changed signature of wait() function