Exit segfault bugfix

Fixed a bug that caused a segmentation fault when quitting the program. To fix the problem, I've used an external function exit() that handle the quitting.