Use while loop properly