fixed another risky while loop