Fixed the bug that the console mode was not properly restored after closing the program.