changed wait() to Thread.sleep()