fix while loop