Fixing wait bug