logic on while was not valid