Added the Wait method at the end of the while loop