while loop worked