Fixed bug at exit