Fixed  while loop