Fixed bug that caused program to crash when exiting.