Changed the main while loop to a do while