Made changes so that the exits do no cause the program to crash