wait properly instead of bad inifite loop