Removed code causing the program to crash when closed