fixed while loop