improved formatting and added another while loop