Changed for loop the while loop