fix while loop issue