changed the way wait() works