Added a while loop and catch