fix crash i while loop