some problem in wait - race conditions