Moved the sleep in getting a window id - more robust.