Fixed bug when exiting program