Added exit() to avoid core dump and improved Makefiles