fixed segfault at exit and return code