fix while loop portion