added try before wait. to make code more efficient.